diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index e19682603..add8446ce 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -9641,19 +9641,11 @@ tl_object_ptr ContactsManager::get_chat_member_object( bool ContactsManager::on_get_channel_error(ChannelId channel_id, const Status &status, const string &source) { LOG(INFO) << "Receive " << status << " in " << channel_id << " from " << source; - if (status.code() == 401) { - // authorization is lost - return true; - } - if (status.code() == 420 || status.code() == 429) { - // flood wait - return true; - } if (status.message() == CSlice("BOT_METHOD_INVALID")) { LOG(ERROR) << "Receive BOT_METHOD_INVALID from " << source; return true; } - if (G()->close_flag()) { + if (G()->is_expected_error(status)) { return true; } if (status.message() == "CHANNEL_PRIVATE" || status.message() == "CHANNEL_PUBLIC_GROUP_NA") { @@ -9675,7 +9667,7 @@ bool ContactsManager::on_get_channel_error(ChannelId channel_id, const Status &s auto debug_channel_object = oneline(to_string(get_supergroup_object(channel_id, c))); if (c->status.is_member()) { LOG(INFO) << "Emulate leaving " << channel_id; - // TODO we also may try to write to public channel + // TODO we also may try to write to a public channel int32 flags = 0; if (c->is_megagroup) { flags |= CHANNEL_FLAG_IS_MEGAGROUP; diff --git a/td/telegram/Global.h b/td/telegram/Global.h index 6fbf7223c..1dfd33487 100644 --- a/td/telegram/Global.h +++ b/td/telegram/Global.h @@ -343,6 +343,19 @@ class Global : public ActorContext { return close_flag_.load(); } + bool is_expected_error(const Status &error) const { + CHECK(error.is_error()); + if (error.code() == 401) { + // authorization is lost + return true; + } + if (error.code() == 420 || error.code() == 429) { + // flood wait + return true; + } + return close_flag(); + } + const std::vector> &get_net_stats_file_callbacks() { return net_stats_file_callbacks_; } diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 55a824736..011994665 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -21413,19 +21413,11 @@ bool MessagesManager::on_update_scheduled_message_id(int64 random_id, ScheduledS } bool MessagesManager::on_get_dialog_error(DialogId dialog_id, const Status &status, const string &source) { - if (status.code() == 401) { - // authorization is lost - return true; - } - if (status.code() == 420 || status.code() == 429) { - // flood wait - return true; - } if (status.message() == CSlice("BOT_METHOD_INVALID")) { LOG(ERROR) << "Receive BOT_METHOD_INVALID from " << source; return true; } - if (G()->close_flag()) { + if (G()->is_expected_error(status)) { return true; }