From 99f1369e8c84cf0eff57b647419652991bbde178 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 22 Feb 2024 22:55:09 +0300 Subject: [PATCH] Add updateQuickReplyShortcuts. --- td/generate/scheme/td_api.tl | 3 +++ td/telegram/QuickReplyManager.cpp | 28 ++++++++++++++++++++++++++++ td/telegram/QuickReplyManager.h | 4 ++++ 3 files changed, 35 insertions(+) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 2d8944b4d..076dd49eb 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -6590,6 +6590,9 @@ updateQuickReplyShortcut shortcut:quickReplyShortcut = Update; //@description A quick reply shortcut was deleted @name The name of the deleted shortcut updateQuickReplyShortcutDeleted name:string = Update; +//@description The list of quick reply shortcuts has changed @shortcuts The new list of existing quick reply shortcuts +updateQuickReplyShortcuts shortcuts:vector = Update; + //@description Basic information about a topic in a forum chat was changed @chat_id Chat identifier @info New information about the topic updateForumTopicInfo chat_id:int53 info:forumTopicInfo = Update; diff --git a/td/telegram/QuickReplyManager.cpp b/td/telegram/QuickReplyManager.cpp index 6b2aede75..31cfb5e4b 100644 --- a/td/telegram/QuickReplyManager.cpp +++ b/td/telegram/QuickReplyManager.cpp @@ -293,6 +293,7 @@ void QuickReplyManager::on_reload_quick_reply_shortcuts( case telegram_api::messages_quickRepliesNotModified::ID: if (!shortcuts_.are_inited_) { shortcuts_.are_inited_ = true; + send_update_quick_reply_shortcuts(); } break; case telegram_api::messages_quickReplies::ID: { @@ -386,12 +387,24 @@ void QuickReplyManager::on_reload_quick_reply_shortcuts( new_shortcuts.push_back(std::move(shortcut)); } } + bool is_list_changed = !shortcuts_.are_inited_ || shortcuts_.shortcuts_.size() != new_shortcuts.size(); + if (!is_list_changed) { + for (size_t i = 0; i < new_shortcuts.size(); i++) { + if (shortcuts_.shortcuts_[i]->name_ != new_shortcuts[i]->name_) { + is_list_changed = true; + break; + } + } + } shortcuts_.shortcuts_ = std::move(new_shortcuts); shortcuts_.are_inited_ = true; for (auto shortcut_id : changed_shortcut_ids) { send_update_quick_reply_shortcut(get_shortcut(shortcut_id), "on_reload_quick_reply_shortcuts 2"); } + if (is_list_changed) { + send_update_quick_reply_shortcuts(); + } break; } } @@ -518,6 +531,17 @@ void QuickReplyManager::send_update_quick_reply_shortcut_deleted(const Shortcut send_closure(G()->td(), &Td::send_update, get_update_quick_reply_shortcut_deleted_object(s)); } +td_api::object_ptr QuickReplyManager::get_update_quick_reply_shortcuts_object() + const { + CHECK(shortcuts_.are_inited_); + return td_api::make_object( + transform(shortcuts_.shortcuts_, [](const unique_ptr &shortcut) { return shortcut->name_; })); +} + +void QuickReplyManager::send_update_quick_reply_shortcuts() { + send_closure(G()->td(), &Td::send_update, get_update_quick_reply_shortcuts_object()); +} + void QuickReplyManager::get_current_state(vector> &updates) const { if (td_->auth_manager_->is_bot()) { return; @@ -526,6 +550,10 @@ void QuickReplyManager::get_current_state(vector get_update_quick_reply_shortcuts_object() const; + + void send_update_quick_reply_shortcuts(); + Shortcuts shortcuts_; Td *td_;