From bfd3d653a719454b35148a5c4f137e8da447d29d Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 2 Dec 2019 19:20:54 +0300 Subject: [PATCH] Support updateDeleteScheduledMessages. GitOrigin-RevId: 9f2d0cf00a3e6ffe20c1b0834cad69fbb0861ad7 --- td/telegram/MessagesManager.cpp | 36 +++++++++++++++++++++++++++++++++ td/telegram/MessagesManager.h | 3 +++ td/telegram/UpdatesManager.cpp | 14 +++++++++---- td/telegram/UpdatesManager.h | 3 ++- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 12667dc5..05510536 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -5729,6 +5729,40 @@ void MessagesManager::on_update_dialog_online_member_count(DialogId dialog_id, i "on_update_channel_online_member_count"); } +void MessagesManager::on_update_delete_scheduled_messages(DialogId dialog_id, + vector &&server_message_ids) { + if (td_->auth_manager_->is_bot()) { + // just in case + return; + } + + if (!dialog_id.is_valid()) { + LOG(ERROR) << "Receive deleted scheduled messages in invalid " << dialog_id; + return; + } + + Dialog *d = get_dialog_force(dialog_id); + if (d == nullptr) { + LOG(INFO) << "Skip updateDeleteScheduledMessages in unknown " << dialog_id; + return; + } + + vector deleted_message_ids; + for (auto server_message_id : server_message_ids) { + if (!server_message_id.is_valid()) { + LOG(ERROR) << "Incoming update tries to delete scheduled message " << server_message_id.get(); + continue; + } + + auto message = do_delete_scheduled_message(d, MessageId(server_message_id, std::numeric_limits::max()), true, + "on_update_delete_scheduled_messages"); + if (message != nullptr) { + deleted_message_ids.push_back(message->message_id.get()); + } + } + send_update_delete_messages(dialog_id, std::move(deleted_message_ids), true, false); +} + void MessagesManager::on_update_include_sponsored_dialog_to_unread_count() { if (td_->auth_manager_->is_bot()) { // just in case @@ -25411,6 +25445,8 @@ MessagesManager::Message *MessagesManager::add_scheduled_message_to_dialog(Dialo } if (old_message_id != message_id) { message = do_delete_scheduled_message(d, old_message_id, false, "add_scheduled_message_to_dialog"); + CHECK(message != nullptr); + send_update_delete_messages(dialog_id, {old_message_id.get()}, false, false); message->message_id = message_id; message->random_y = get_random_y(message->message_id); } else { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 37f43c40..16e505ca 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -37,6 +37,7 @@ #include "td/telegram/NotificationSettings.h" #include "td/telegram/ReplyMarkup.h" #include "td/telegram/RestrictionReason.h" +#include "td/telegram/ScheduledServerMessageId.h" #include "td/telegram/SecretChatId.h" #include "td/telegram/SecretInputMedia.h" #include "td/telegram/ServerMessageId.h" @@ -319,6 +320,8 @@ class MessagesManager : public Actor { void on_update_dialog_online_member_count(DialogId dialog_id, int32 online_member_count, bool is_from_server); + void on_update_delete_scheduled_messages(DialogId dialog_id, vector &&server_message_ids); + void on_update_include_sponsored_dialog_to_unread_count(); void on_user_dialog_action(DialogId dialog_id, UserId user_id, tl_object_ptr &&action, int32 date, diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index 63242630..88b58356 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -31,6 +31,7 @@ #include "td/telegram/PollId.h" #include "td/telegram/PollManager.h" #include "td/telegram/PrivacyManager.h" +#include "td/telegram/ScheduledServerMessageId.h" #include "td/telegram/SecretChatId.h" #include "td/telegram/SecretChatsManager.h" #include "td/telegram/ServerMessageId.h" @@ -1911,15 +1912,20 @@ void UpdatesManager::on_update(tl_object_ptr up td_->poll_manager_->on_get_poll(PollId(update->poll_id_), std::move(update->poll_), std::move(update->results_)); } +void UpdatesManager::on_update(tl_object_ptr update, + bool /*force_apply*/) { + vector message_ids = transform(update->messages_, [](int32 scheduled_server_message_id) { + return ScheduledServerMessageId(scheduled_server_message_id); + }); + + td_->messages_manager_->on_update_delete_scheduled_messages(DialogId(update->peer_), std::move(message_ids)); +} + // unsupported updates void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { } -void UpdatesManager::on_update(tl_object_ptr update, - bool /*force_apply*/) { -} - void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { } diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index 2cacc494..2293c884 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -280,10 +280,11 @@ class UpdatesManager : public Actor { void on_update(tl_object_ptr update, bool /*force_apply*/); + void on_update(tl_object_ptr update, bool /*force_apply*/); + // unsupported updates void on_update(tl_object_ptr update, bool /*force_apply*/); - void on_update(tl_object_ptr update, bool /*force_apply*/); void on_update(tl_object_ptr update, bool /*force_apply*/); };