Add and use MessagesManager::on_get_message_error.

This commit is contained in:
levlam 2023-11-12 22:55:48 +03:00
parent 24f74a018e
commit 413556bab7
4 changed files with 44 additions and 29 deletions

View File

@ -83,16 +83,13 @@ class GetBotCallbackAnswerQuery final : public Td::ResultHandler {
} }
void on_error(Status status) final { void on_error(Status status) final {
if (status.message() == "DATA_INVALID" || status.message() == "MESSAGE_ID_INVALID") { td_->messages_manager_->on_get_message_error(dialog_id_, message_id_, status, "GetBotCallbackAnswerQuery");
td_->messages_manager_->get_message_from_server({dialog_id_, message_id_}, Auto(), "GetBotCallbackAnswerQuery"); if (status.message() == "BOT_RESPONSE_TIMEOUT") {
} else if (status.message() == "BOT_RESPONSE_TIMEOUT") {
status = Status::Error(502, "The bot is not responding"); status = Status::Error(502, "The bot is not responding");
} }
if (status.code() == 502 && td_->messages_manager_->is_message_edited_recently({dialog_id_, message_id_}, 31)) { if (status.code() == 502 && td_->messages_manager_->is_message_edited_recently({dialog_id_, message_id_}, 31)) {
return promise_.set_value(td_api::make_object<td_api::callbackQueryAnswer>()); return promise_.set_value(td_api::make_object<td_api::callbackQueryAnswer>());
} }
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetBotCallbackAnswerQuery");
promise_.set_error(std::move(status)); promise_.set_error(std::move(status));
} }
}; };

View File

@ -277,13 +277,7 @@ class GetDiscussionMessageQuery final : public Td::ResultHandler {
} }
void on_error(Status status) final { void on_error(Status status) final {
if (expected_dialog_id_ == dialog_id_) { td_->messages_manager_->on_get_message_error(dialog_id_, message_id_, status, "GetDiscussionMessageQuery");
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetDiscussionMessageQuery");
}
if (status.message() == "MSG_ID_INVALID") {
td_->messages_manager_->get_message_from_server({dialog_id_, message_id_}, Promise<Unit>(),
"GetDiscussionMessageQuery");
}
promise_.set_error(std::move(status)); promise_.set_error(std::move(status));
} }
}; };
@ -428,6 +422,7 @@ class GetScheduledMessagesQuery final : public Td::ResultHandler {
class UpdateDialogPinnedMessageQuery final : public Td::ResultHandler { class UpdateDialogPinnedMessageQuery final : public Td::ResultHandler {
Promise<Unit> promise_; Promise<Unit> promise_;
DialogId dialog_id_; DialogId dialog_id_;
MessageId message_id_;
public: public:
explicit UpdateDialogPinnedMessageQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) { explicit UpdateDialogPinnedMessageQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
@ -435,6 +430,7 @@ class UpdateDialogPinnedMessageQuery final : public Td::ResultHandler {
void send(DialogId dialog_id, MessageId message_id, bool is_unpin, bool disable_notification, bool only_for_self) { void send(DialogId dialog_id, MessageId message_id, bool is_unpin, bool disable_notification, bool only_for_self) {
dialog_id_ = dialog_id; dialog_id_ = dialog_id;
message_id_ = message_id;
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write); auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) { if (input_peer == nullptr) {
LOG(INFO) << "Can't update pinned message in " << dialog_id; LOG(INFO) << "Can't update pinned message in " << dialog_id;
@ -468,7 +464,7 @@ class UpdateDialogPinnedMessageQuery final : public Td::ResultHandler {
} }
void on_error(Status status) final { void on_error(Status status) final {
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "UpdateDialogPinnedMessageQuery"); td_->messages_manager_->on_get_message_error(dialog_id_, message_id_, status, "UpdateDialogPinnedMessageQuery");
promise_.set_error(std::move(status)); promise_.set_error(std::move(status));
} }
}; };
@ -476,6 +472,7 @@ class UpdateDialogPinnedMessageQuery final : public Td::ResultHandler {
class UnpinAllMessagesQuery final : public Td::ResultHandler { class UnpinAllMessagesQuery final : public Td::ResultHandler {
Promise<AffectedHistory> promise_; Promise<AffectedHistory> promise_;
DialogId dialog_id_; DialogId dialog_id_;
MessageId top_thread_message_id_;
public: public:
explicit UnpinAllMessagesQuery(Promise<AffectedHistory> &&promise) : promise_(std::move(promise)) { explicit UnpinAllMessagesQuery(Promise<AffectedHistory> &&promise) : promise_(std::move(promise)) {
@ -483,6 +480,7 @@ class UnpinAllMessagesQuery final : public Td::ResultHandler {
void send(DialogId dialog_id, MessageId top_thread_message_id) { void send(DialogId dialog_id, MessageId top_thread_message_id) {
dialog_id_ = dialog_id; dialog_id_ = dialog_id;
top_thread_message_id_ = top_thread_message_id;
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Write); auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Write);
if (input_peer == nullptr) { if (input_peer == nullptr) {
@ -508,7 +506,7 @@ class UnpinAllMessagesQuery final : public Td::ResultHandler {
} }
void on_error(Status status) final { void on_error(Status status) final {
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "UnpinAllMessagesQuery"); td_->messages_manager_->on_get_message_error(dialog_id_, top_thread_message_id_, status, "UnpinAllMessagesQuery");
promise_.set_error(std::move(status)); promise_.set_error(std::move(status));
} }
}; };
@ -516,6 +514,7 @@ class UnpinAllMessagesQuery final : public Td::ResultHandler {
class GetMessageReadParticipantsQuery final : public Td::ResultHandler { class GetMessageReadParticipantsQuery final : public Td::ResultHandler {
Promise<MessageViewers> promise_; Promise<MessageViewers> promise_;
DialogId dialog_id_; DialogId dialog_id_;
MessageId message_id_;
public: public:
explicit GetMessageReadParticipantsQuery(Promise<MessageViewers> &&promise) : promise_(std::move(promise)) { explicit GetMessageReadParticipantsQuery(Promise<MessageViewers> &&promise) : promise_(std::move(promise)) {
@ -523,6 +522,7 @@ class GetMessageReadParticipantsQuery final : public Td::ResultHandler {
void send(DialogId dialog_id, MessageId message_id) { void send(DialogId dialog_id, MessageId message_id) {
dialog_id_ = dialog_id; dialog_id_ = dialog_id;
message_id_ = message_id;
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read); auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
CHECK(input_peer != nullptr); CHECK(input_peer != nullptr);
send_query(G()->net_query_creator().create(telegram_api::messages_getMessageReadParticipants( send_query(G()->net_query_creator().create(telegram_api::messages_getMessageReadParticipants(
@ -539,7 +539,7 @@ class GetMessageReadParticipantsQuery final : public Td::ResultHandler {
} }
void on_error(Status status) final { void on_error(Status status) final {
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetMessageReadParticipantsQuery"); td_->messages_manager_->on_get_message_error(dialog_id_, message_id_, status, "GetMessageReadParticipantsQuery");
promise_.set_error(std::move(status)); promise_.set_error(std::move(status));
} }
}; };
@ -591,7 +591,8 @@ class ExportChannelMessageLinkQuery final : public Td::ResultHandler {
void on_error(Status status) final { void on_error(Status status) final {
if (!ignore_result_) { if (!ignore_result_) {
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "ExportChannelMessageLinkQuery"); td_->messages_manager_->on_get_message_error(DialogId(channel_id_), message_id_, status,
"ExportChannelMessageLinkQuery");
} }
promise_.set_error(std::move(status)); promise_.set_error(std::move(status));
} }
@ -2739,6 +2740,7 @@ class DeleteHistoryQuery final : public Td::ResultHandler {
class DeleteTopicHistoryQuery final : public Td::ResultHandler { class DeleteTopicHistoryQuery final : public Td::ResultHandler {
Promise<AffectedHistory> promise_; Promise<AffectedHistory> promise_;
ChannelId channel_id_; ChannelId channel_id_;
MessageId top_thread_message_id_;
public: public:
explicit DeleteTopicHistoryQuery(Promise<AffectedHistory> &&promise) : promise_(std::move(promise)) { explicit DeleteTopicHistoryQuery(Promise<AffectedHistory> &&promise) : promise_(std::move(promise)) {
@ -2747,6 +2749,7 @@ class DeleteTopicHistoryQuery final : public Td::ResultHandler {
void send(DialogId dialog_id, MessageId top_thread_message_id) { void send(DialogId dialog_id, MessageId top_thread_message_id) {
CHECK(dialog_id.get_type() == DialogType::Channel); CHECK(dialog_id.get_type() == DialogType::Channel);
channel_id_ = dialog_id.get_channel_id(); channel_id_ = dialog_id.get_channel_id();
top_thread_message_id_ = top_thread_message_id;
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id_); auto input_channel = td_->contacts_manager_->get_input_channel(channel_id_);
if (input_channel == nullptr) { if (input_channel == nullptr) {
@ -2767,7 +2770,8 @@ class DeleteTopicHistoryQuery final : public Td::ResultHandler {
} }
void on_error(Status status) final { void on_error(Status status) final {
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "DeleteTopicHistoryQuery"); td_->messages_manager_->on_get_message_error(DialogId(channel_id_), top_thread_message_id_, status,
"DeleteTopicHistoryQuery");
promise_.set_error(std::move(status)); promise_.set_error(std::move(status));
} }
}; };
@ -3727,7 +3731,7 @@ class EditMessageQuery final : public Td::ResultHandler {
if (!td_->auth_manager_->is_bot() && status.message() == "MESSAGE_NOT_MODIFIED") { if (!td_->auth_manager_->is_bot() && status.message() == "MESSAGE_NOT_MODIFIED") {
return promise_.set_value(0); return promise_.set_value(0);
} }
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "EditMessageQuery"); td_->messages_manager_->on_get_message_error(dialog_id_, message_id_, status, "EditMessageQuery");
promise_.set_error(std::move(status)); promise_.set_error(std::move(status));
} }
}; };
@ -3795,6 +3799,7 @@ class ForwardMessagesQuery final : public Td::ResultHandler {
vector<int64> random_ids_; vector<int64> random_ids_;
DialogId from_dialog_id_; DialogId from_dialog_id_;
DialogId to_dialog_id_; DialogId to_dialog_id_;
MessageId message_id_;
public: public:
explicit ForwardMessagesQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) { explicit ForwardMessagesQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
@ -3806,6 +3811,9 @@ class ForwardMessagesQuery final : public Td::ResultHandler {
random_ids_ = random_ids; random_ids_ = random_ids;
from_dialog_id_ = from_dialog_id; from_dialog_id_ = from_dialog_id;
to_dialog_id_ = to_dialog_id; to_dialog_id_ = to_dialog_id;
if (message_ids.size() == 1) {
message_id_ = message_ids[0];
}
auto to_input_peer = td_->messages_manager_->get_input_peer(to_dialog_id, AccessRights::Write); auto to_input_peer = td_->messages_manager_->get_input_peer(to_dialog_id, AccessRights::Write);
if (to_input_peer == nullptr) { if (to_input_peer == nullptr) {
@ -3902,6 +3910,10 @@ class ForwardMessagesQuery final : public Td::ResultHandler {
if (status.code() == 400 && status.message() == CSlice("SEND_AS_PEER_INVALID")) { if (status.code() == 400 && status.message() == CSlice("SEND_AS_PEER_INVALID")) {
td_->messages_manager_->reload_dialog_info_full(to_dialog_id_, "SEND_AS_PEER_INVALID"); td_->messages_manager_->reload_dialog_info_full(to_dialog_id_, "SEND_AS_PEER_INVALID");
} }
if (message_id_.is_valid() && status.message() == CSlice("MESSAGE_ID_INVALID")) {
td_->messages_manager_->get_message_from_server({from_dialog_id_, message_id_}, Promise<Unit>(),
"ForwardMessagesQuery");
}
for (auto &random_id : random_ids_) { for (auto &random_id : random_ids_) {
td_->messages_manager_->on_send_message_fail(random_id, status.clone()); td_->messages_manager_->on_send_message_fail(random_id, status.clone());
} }
@ -4008,17 +4020,17 @@ class SetTypingQuery final : public Td::ResultHandler {
explicit SetTypingQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) { explicit SetTypingQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
} }
NetQueryRef send(DialogId dialog_id, tl_object_ptr<telegram_api::InputPeer> &&input_peer, MessageId message_id, NetQueryRef send(DialogId dialog_id, tl_object_ptr<telegram_api::InputPeer> &&input_peer,
tl_object_ptr<telegram_api::SendMessageAction> &&action) { MessageId top_thread_message_id, tl_object_ptr<telegram_api::SendMessageAction> &&action) {
dialog_id_ = dialog_id; dialog_id_ = dialog_id;
CHECK(input_peer != nullptr); CHECK(input_peer != nullptr);
int32 flags = 0; int32 flags = 0;
if (message_id.is_valid()) { if (top_thread_message_id.is_valid()) {
flags |= telegram_api::messages_setTyping::TOP_MSG_ID_MASK; flags |= telegram_api::messages_setTyping::TOP_MSG_ID_MASK;
} }
auto query = G()->net_query_creator().create(telegram_api::messages_setTyping( auto query = G()->net_query_creator().create(telegram_api::messages_setTyping(
flags, std::move(input_peer), message_id.get_server_message_id().get(), std::move(action))); flags, std::move(input_peer), top_thread_message_id.get_server_message_id().get(), std::move(action)));
query->total_timeout_limit_ = 2; query->total_timeout_limit_ = 2;
auto result = query.get_weak(); auto result = query.get_weak();
generation_ = result.generation(); generation_ = result.generation();
@ -28900,6 +28912,16 @@ bool MessagesManager::on_get_dialog_error(DialogId dialog_id, const Status &stat
return false; return false;
} }
bool MessagesManager::on_get_message_error(DialogId dialog_id, MessageId message_id, const Status &status,
const char *source) {
if (status.message() == "MSG_ID_INVALID" || status.message() == "MESSAGE_ID_INVALID" ||
status.message() == "DATA_INVALID") {
td_->messages_manager_->get_message_from_server({dialog_id, message_id}, Promise<Unit>(), source);
return true;
}
return on_get_dialog_error(dialog_id, status, source);
}
void MessagesManager::on_dialog_updated(DialogId dialog_id, const char *source) { void MessagesManager::on_dialog_updated(DialogId dialog_id, const char *source) {
if (G()->use_message_database()) { if (G()->use_message_database()) {
LOG(INFO) << "Update " << dialog_id << " from " << source; LOG(INFO) << "Update " << dialog_id << " from " << source;

View File

@ -935,6 +935,8 @@ class MessagesManager final : public Actor {
bool on_get_dialog_error(DialogId dialog_id, const Status &status, const char *source); bool on_get_dialog_error(DialogId dialog_id, const Status &status, const char *source);
bool on_get_message_error(DialogId dialog_id, MessageId message_id, const Status &status, const char *source);
void on_send_message_get_quick_ack(int64 random_id); void on_send_message_get_quick_ack(int64 random_id);
void check_send_message_result(int64 random_id, DialogId dialog_id, const telegram_api::Updates *updates_ptr, void check_send_message_result(int64 random_id, DialogId dialog_id, const telegram_api::Updates *updates_ptr,

View File

@ -82,13 +82,7 @@ class GetPollResultsQuery final : public Td::ResultHandler {
} }
void on_error(Status status) final { void on_error(Status status) final {
if (status.message() == "MESSAGE_ID_INVALID") { if (!td_->messages_manager_->on_get_message_error(dialog_id_, message_id_, status, "GetPollResultsQuery")) {
// likely, the message has already been deleted
if (dialog_id_.get_type() == DialogType::Channel) {
td_->messages_manager_->get_message_from_server({dialog_id_, message_id_}, Promise<Unit>(),
"GetPollResultsQuery");
}
} else if (!td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetPollResultsQuery")) {
LOG(ERROR) << "Receive " << status << ", while trying to get results of " << poll_id_; LOG(ERROR) << "Receive " << status << ", while trying to get results of " << poll_id_;
} }
promise_.set_error(std::move(status)); promise_.set_error(std::move(status));