Try fetching the status 2 times

This commit is contained in:
tastytea 2018-05-27 01:24:11 +02:00
parent ed537c850f
commit 1273f72e4b
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
2 changed files with 38 additions and 24 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7) cmake_minimum_required (VERSION 3.7)
project (expandurl-mastodon project (expandurl-mastodon
VERSION 0.7.0 VERSION 0.7.1
LANGUAGES CXX LANGUAGES CXX
) )

View File

@ -298,32 +298,46 @@ const std::uint_fast64_t Listener::get_parent_id(const Easy::Notification &notif
string answer; string answer;
std::uint_fast16_t ret; std::uint_fast16_t ret;
// Fetch full status // Retry up to 2 times
ret = _masto->get(API::v1::search, {{ "q", { notif.status().url() }}}, for (std::uint_fast8_t retries = 1; retries <= 2; ++retries)
answer);
if (ret > 0 || !Easy::Status(answer).valid())
{ {
syslog(LOG_ERR, "Error %u: Could not fetch status (in %s).", // Fetch full status
ret, __FUNCTION__); ret = _masto->get(API::v1::search, {{ "q", { notif.status().url() }}},
return 0; answer);
if (ret > 0 || !Easy::Status(answer).valid())
{
syslog(LOG_ERR, "Error %u: Could not fetch status (in %s).",
ret, __FUNCTION__);
return 0;
}
ret = _masto->get(API::v1::statuses_id,
{{ "id", { std::to_string(notif.status().id()) }}},
answer);
if (ret > 0)
{
syslog(LOG_ERR, "Error %u: Could not get status (in %s).",
ret, __FUNCTION__);
return 0;
}
else
{
_config["last_id"] = std::to_string(notif.id());
const Easy::Status s(answer);
// If parent is found, return ID; else retry
if (s.in_reply_to_id() != 0)
{
return s.in_reply_to_id();
}
else
{
std::this_thread::sleep_for(std::chrono::seconds(2));
}
}
} }
ret = _masto->get(API::v1::statuses_id,
{{ "id", { std::to_string(notif.status().id()) }}},
answer);
if (ret > 0)
{
syslog(LOG_ERR, "Error %u: Could not get status (in %s).",
ret, __FUNCTION__);
return 0;
}
else
{
_config["last_id"] = std::to_string(notif.id());
Easy::Status s(answer);
return s.in_reply_to_id();
}
return 0; return 0;
} }