From a8377db05de76270994e618e55ae64e3f6bab221 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 25 Dec 2020 02:53:00 +0300 Subject: [PATCH] Simplify handling of updateNewChannelMessage and updateEditChannelMessage. --- td/telegram/MessagesManager.cpp | 85 ++++----------------------------- td/telegram/MessagesManager.h | 6 --- td/telegram/UpdatesManager.cpp | 38 +++++++++------ 3 files changed, 32 insertions(+), 97 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 50a56051a..cc7661a32 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -6396,80 +6396,6 @@ void MessagesManager::on_update_service_notification(tl_object_ptr &&update, - Promise &&promise) { - int new_pts = update->pts_; - int pts_count = update->pts_count_; - DialogId dialog_id = get_message_dialog_id(update->message_); - switch (dialog_id.get_type()) { - case DialogType::None: - promise.set_value(Unit()); - return; - case DialogType::User: - case DialogType::Chat: - case DialogType::SecretChat: - LOG(ERROR) << "Receive updateNewChannelMessage in wrong " << dialog_id; - promise.set_value(Unit()); - return; - case DialogType::Channel: { - auto channel_id = dialog_id.get_channel_id(); - if (!td_->contacts_manager_->have_channel(channel_id)) { - // if min channel was received - if (td_->contacts_manager_->have_min_channel(channel_id)) { - td_->updates_manager_->schedule_get_difference("on_update_new_channel_message"); - promise.set_value(Unit()); // TODO postpone - return; - } - } - // Ok - break; - } - default: - UNREACHABLE(); - return; - } - - add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count, std::move(promise), - "on_update_new_channel_message"); -} - -void MessagesManager::on_update_edit_channel_message(tl_object_ptr &&update, - Promise &&promise) { - int new_pts = update->pts_; - int pts_count = update->pts_count_; - DialogId dialog_id = get_message_dialog_id(update->message_); - switch (dialog_id.get_type()) { - case DialogType::None: - promise.set_value(Unit()); - return; - case DialogType::User: - case DialogType::Chat: - case DialogType::SecretChat: - LOG(ERROR) << "Receive updateEditChannelMessage in wrong " << dialog_id; - promise.set_value(Unit()); - return; - case DialogType::Channel: { - auto channel_id = dialog_id.get_channel_id(); - if (!td_->contacts_manager_->have_channel(channel_id)) { - // if min channel was received - if (td_->contacts_manager_->have_min_channel(channel_id)) { - td_->updates_manager_->schedule_get_difference("on_update_edit_channel_message"); - promise.set_value(Unit()); // TODO postpone - return; - } - } - // Ok - break; - } - default: - UNREACHABLE(); - return; - } - - add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count, std::move(promise), - "on_update_edit_channel_message"); -} - void MessagesManager::on_update_read_channel_inbox(tl_object_ptr &&update) { ChannelId channel_id(update->channel_id_); if (!channel_id.is_valid()) { @@ -7123,7 +7049,8 @@ void MessagesManager::add_pending_channel_update(DialogId dialog_id, tl_object_p LOG(INFO) << "Receive from " << source << " pending " << to_string(update); CHECK(update != nullptr); if (dialog_id.get_type() != DialogType::Channel) { - LOG(ERROR) << "Receive update in invalid " << dialog_id << " from " << source << ": " << oneline(to_string(update)); + LOG(ERROR) << "Receive channel update in invalid " << dialog_id << " from " << source << ": " + << oneline(to_string(update)); promise.set_value(Unit()); return; } @@ -7134,6 +7061,13 @@ void MessagesManager::add_pending_channel_update(DialogId dialog_id, tl_object_p return; } + auto channel_id = dialog_id.get_channel_id(); + if (!td_->contacts_manager_->have_channel(channel_id) && td_->contacts_manager_->have_min_channel(channel_id)) { + td_->updates_manager_->schedule_get_difference("on_update_new_channel_message"); + promise.set_value(Unit()); + return; + } + // TODO need to save all updates that can change result of running queries not associated with pts (for example // getHistory) and apply them to result of these queries @@ -7141,7 +7075,6 @@ void MessagesManager::add_pending_channel_update(DialogId dialog_id, tl_object_p if (d == nullptr) { auto pts = load_channel_pts(dialog_id); if (pts > 0) { - auto channel_id = dialog_id.get_channel_id(); if (!td_->contacts_manager_->have_channel(channel_id)) { // do not create dialog if there is no info about the channel LOG(INFO) << "There is no info about " << channel_id << ", so ignore " << oneline(to_string(update)); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 09a626999..c922b07c0 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -343,12 +343,6 @@ class MessagesManager : public Actor { void on_update_service_notification(tl_object_ptr &&update, bool skip_new_entities, Promise &&promise); - void on_update_new_channel_message(tl_object_ptr &&update, - Promise &&promise); - - void on_update_edit_channel_message(tl_object_ptr &&update, - Promise &&promise); - void on_update_read_channel_inbox(tl_object_ptr &&update); void on_update_read_channel_outbox(tl_object_ptr &&update); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 975a6c650..b8bdbd003 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -1696,12 +1696,16 @@ void UpdatesManager::on_update(tl_object_ptr upd int new_pts = update->pts_; int pts_count = update->pts_count_; td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise), - "on_updateNewMessage"); + "updateNewMessage"); } void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise) { - td_->messages_manager_->on_update_new_channel_message(std::move(update), std::move(promise)); + DialogId dialog_id = MessagesManager::get_message_dialog_id(update->message_); + int new_pts = update->pts_; + int pts_count = update->pts_count_; + td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count, + std::move(promise), "updateNewChannelMessage"); } void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, @@ -1721,7 +1725,7 @@ void UpdatesManager::on_update(tl_object_ptrpts_; int pts_count = update->pts_count_; td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise), - "on_updateReadMessagesContents"); + "updateReadMessagesContents"); } void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, @@ -1729,7 +1733,7 @@ void UpdatesManager::on_update(tl_object_ptr up int new_pts = update->pts_; int pts_count = update->pts_count_; td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise), - "on_updateEditMessage"); + "updateEditMessage"); } void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, @@ -1738,11 +1742,11 @@ void UpdatesManager::on_update(tl_object_ptr int pts_count = update->pts_count_; if (update->messages_.empty()) { td_->messages_manager_->add_pending_update(make_tl_object(), new_pts, pts_count, force_apply, - Promise(), "on_updateDeleteMessages"); + Promise(), "updateDeleteMessages"); promise.set_value(Unit()); } else { td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise), - "on_updateDeleteMessages"); + "updateDeleteMessages"); } } @@ -1754,7 +1758,7 @@ void UpdatesManager::on_update(tl_object_ptrstill_unread_count_ = -1; } td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise), - "on_updateReadHistoryInbox"); + "updateReadHistoryInbox"); } void UpdatesManager::on_update(tl_object_ptr update, bool force_apply, @@ -1762,7 +1766,7 @@ void UpdatesManager::on_update(tl_object_ptrpts_; int pts_count = update->pts_count_; td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise), - "on_updateReadHistoryOutbox"); + "updateReadHistoryOutbox"); } void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, @@ -1811,7 +1815,11 @@ void UpdatesManager::on_update(tl_object_ptr update void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, Promise &&promise) { - td_->messages_manager_->on_update_edit_channel_message(std::move(update), std::move(promise)); + DialogId dialog_id = MessagesManager::get_message_dialog_id(update->message_); + int new_pts = update->pts_; + int pts_count = update->pts_count_; + td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count, + std::move(promise), "updateEditChannelMessage"); } void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, @@ -1820,7 +1828,7 @@ void UpdatesManager::on_update(tl_object_ptrpts_; int pts_count = update->pts_count_; td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count, - std::move(promise), "on_updateDeleteChannelMessages"); + std::move(promise), "updateDeleteChannelMessages"); } void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, @@ -1882,7 +1890,7 @@ void UpdatesManager::on_update(tl_object_ptr int new_pts = update->pts_; int pts_count = update->pts_count_; td_->messages_manager_->add_pending_update(std::move(update), new_pts, pts_count, force_apply, std::move(promise), - "on_updatePinnedMessages"); + "updatePinnedMessages"); } void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, @@ -1891,7 +1899,7 @@ void UpdatesManager::on_update(tl_object_ptrpts_; int pts_count = update->pts_count_; td_->messages_manager_->add_pending_channel_update(dialog_id, std::move(update), new_pts, pts_count, - std::move(promise), "on_updatePinnedChannelMessages"); + std::move(promise), "updatePinnedChannelMessages"); } void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/, @@ -1941,7 +1949,7 @@ void UpdatesManager::on_update(tl_object_ptr update Promise &&promise) { td_->web_pages_manager_->on_get_web_page(std::move(update->webpage_), DialogId()); td_->messages_manager_->add_pending_update(make_tl_object(), update->pts_, update->pts_count_, - force_apply, Promise(), "on_updateWebPage"); + force_apply, Promise(), "updateWebPage"); promise.set_value(Unit()); } @@ -1950,7 +1958,7 @@ void UpdatesManager::on_update(tl_object_ptr td_->web_pages_manager_->on_get_web_page(std::move(update->webpage_), DialogId()); DialogId dialog_id(ChannelId(update->channel_id_)); td_->messages_manager_->add_pending_channel_update(dialog_id, make_tl_object(), update->pts_, - update->pts_count_, Promise(), "on_updateChannelWebPage"); + update->pts_count_, Promise(), "updateChannelWebPage"); promise.set_value(Unit()); } @@ -1963,7 +1971,7 @@ void UpdatesManager::on_update(tl_object_ptr up } td_->messages_manager_->add_pending_update(make_tl_object(), update->pts_, update->pts_count_, - force_apply, Promise(), "on_updateFolderPeers"); + force_apply, Promise(), "updateFolderPeers"); promise.set_value(Unit()); }