Query max_toot_chars the first time get_max_chars() is called.
This commit is contained in:
parent
6663cca653
commit
0638f8fe9a
|
@ -94,10 +94,7 @@ public:
|
||||||
* @since 0.1.0
|
* @since 0.1.0
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
inline uint64_t get_max_chars() const
|
uint64_t get_max_chars();
|
||||||
{
|
|
||||||
return _max_chars;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const string _hostname;
|
const string _hostname;
|
||||||
|
|
|
@ -27,7 +27,14 @@ Instance::Instance(const string_view &hostname, const string_view &access_token)
|
||||||
: _hostname{hostname}
|
: _hostname{hostname}
|
||||||
, _baseuri{"https://" + _hostname}
|
, _baseuri{"https://" + _hostname}
|
||||||
, _access_token{access_token}
|
, _access_token{access_token}
|
||||||
, _max_chars{500}
|
, _max_chars{0}
|
||||||
|
{}
|
||||||
|
|
||||||
|
uint64_t Instance::get_max_chars()
|
||||||
|
{
|
||||||
|
constexpr uint64_t default_max_chars{500};
|
||||||
|
|
||||||
|
if (_max_chars == 0)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -36,7 +43,8 @@ Instance::Instance(const string_view &hostname, const string_view &access_token)
|
||||||
_baseuri + "/api/v1/instance")};
|
_baseuri + "/api/v1/instance")};
|
||||||
if (!answer)
|
if (!answer)
|
||||||
{
|
{
|
||||||
return;
|
debuglog << "Could not get instance info.\n";
|
||||||
|
return default_max_chars;
|
||||||
}
|
}
|
||||||
|
|
||||||
_max_chars = [&answer]
|
_max_chars = [&answer]
|
||||||
|
@ -46,7 +54,7 @@ Instance::Instance(const string_view &hostname, const string_view &access_token)
|
||||||
if (pos_start == string::npos)
|
if (pos_start == string::npos)
|
||||||
{
|
{
|
||||||
debuglog << "max_toot_chars not found.\n";
|
debuglog << "max_toot_chars not found.\n";
|
||||||
return static_cast<uint64_t>(500);
|
return default_max_chars;
|
||||||
}
|
}
|
||||||
pos_start = body.find(':', pos_start) + 1;
|
pos_start = body.find(':', pos_start) + 1;
|
||||||
const size_t pos_end{body.find(',', pos_start)};
|
const size_t pos_end{body.find(',', pos_start)};
|
||||||
|
@ -63,4 +71,7 @@ Instance::Instance(const string_view &hostname, const string_view &access_token)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return _max_chars;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace mastodonpp
|
} // namespace mastodonpp
|
||||||
|
|
Loading…
Reference in New Issue
Block a user