From 1d76beadeb64378671acbf2dc119eac425f83273 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 22 Feb 2024 23:04:36 +0300 Subject: [PATCH] Replace getQuickReplyShortcuts with loadQuickReplyShortcuts. --- td/generate/scheme/td_api.tl | 9 +++------ td/telegram/QuickReplyManager.cpp | 23 ++++------------------- td/telegram/QuickReplyManager.h | 8 +++----- td/telegram/Td.cpp | 4 ++-- td/telegram/Td.h | 2 +- td/telegram/cli.cpp | 4 ++-- 6 files changed, 15 insertions(+), 35 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 076dd49eb..8c75115fb 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3738,9 +3738,6 @@ quickReplyMessage id:int53 sending_state:MessageSendingState forward_info:messag //@message_count The total number of messages in the shortcut quickReplyShortcut name:string first_message:quickReplyMessage message_count:int32 = QuickReplyShortcut; -//@description Represents a list of quick reply shortcuts created by the current user @shortcuts A list of shortcuts -quickReplyShortcuts shortcuts:vector = QuickReplyShortcuts; - //@class PublicForward @description Describes a public forward or repost of a story @@ -6583,7 +6580,7 @@ updateSavedMessagesTopic topic:savedMessagesTopic = Update; //@description Number of Saved Messages topics has changed @topic_count Approximate total number of Saved Messages topics updateSavedMessagesTopicCount topic_count:int32 = Update; -//@description Basic information about a quick reply shortcut has changed. This update is guaranteed to come before the quick shortcut identifier is returned to the application +//@description Basic information about a quick reply shortcut has changed. This update is guaranteed to come before the quick shortcut name is returned to the application //@shortcut New data about the shortcut updateQuickReplyShortcut shortcut:quickReplyShortcut = Update; @@ -7720,8 +7717,8 @@ editInlineMessageReplyMarkup inline_message_id:string reply_markup:ReplyMarkup = editMessageSchedulingState chat_id:int53 message_id:int53 scheduling_state:MessageSchedulingState = Ok; -//@description Returns shortcuts created by the current user -getQuickReplyShortcuts = QuickReplyShortcuts; +//@description Loads quick reply shortcuts created by the current user. The loaded topics will be sent through updateQuickReplyShortcuts +loadQuickReplyShortcuts = Ok; //@description Returns list of custom emojis, which can be used as forum topic icon by all users diff --git a/td/telegram/QuickReplyManager.cpp b/td/telegram/QuickReplyManager.cpp index 31cfb5e4b..3099eb8ed 100644 --- a/td/telegram/QuickReplyManager.cpp +++ b/td/telegram/QuickReplyManager.cpp @@ -249,24 +249,15 @@ td_api::object_ptr QuickReplyManager::get_quick_repl s->name_, get_quick_reply_message_object(s->messages_[0].get(), source), get_shortcut_message_count(s)); } -td_api::object_ptr QuickReplyManager::get_quick_reply_shortcuts_object( - const char *source) const { - CHECK(shortcuts_.are_inited_); - return td_api::make_object( - transform(shortcuts_.shortcuts_, [this, source](const unique_ptr &shortcut) { - return get_quick_reply_shortcut_object(shortcut.get(), source); - })); -} - -void QuickReplyManager::get_quick_reply_shortcuts(Promise> &&promise) { +void QuickReplyManager::get_quick_reply_shortcuts(Promise &&promise) { if (shortcuts_.are_inited_) { - return promise.set_value(get_quick_reply_shortcuts_object("get_quick_reply_shortcuts")); + return promise.set_value(Unit()); } load_quick_reply_shortcuts(std::move(promise)); } -void QuickReplyManager::load_quick_reply_shortcuts(Promise> &&promise) { +void QuickReplyManager::load_quick_reply_shortcuts(Promise &&promise) { shortcuts_.load_queries_.push_back(std::move(promise)); if (shortcuts_.load_queries_.size() != 1) { return; @@ -412,13 +403,7 @@ void QuickReplyManager::on_reload_quick_reply_shortcuts( } void QuickReplyManager::on_load_quick_reply_success() { - auto promises = std::move(shortcuts_.load_queries_); - reset_to_empty(shortcuts_.load_queries_); - for (auto &promise : promises) { - if (promise) { - promise.set_value(get_quick_reply_shortcuts_object("on_load_quick_reply_success")); - } - } + set_promises(shortcuts_.load_queries_); } void QuickReplyManager::on_load_quick_reply_fail(Status error) { diff --git a/td/telegram/QuickReplyManager.h b/td/telegram/QuickReplyManager.h index 124c5d889..f0e3326ab 100644 --- a/td/telegram/QuickReplyManager.h +++ b/td/telegram/QuickReplyManager.h @@ -28,7 +28,7 @@ class QuickReplyManager final : public Actor { public: QuickReplyManager(Td *td, ActorShared<> parent); - void get_quick_reply_shortcuts(Promise> &&promise); + void get_quick_reply_shortcuts(Promise &&promise); void reload_quick_reply_shortcuts(); @@ -103,7 +103,7 @@ class QuickReplyManager final : public Actor { vector> shortcuts_; bool are_inited_ = false; - vector>> load_queries_; + vector> load_queries_; }; void tear_down() final; @@ -126,11 +126,9 @@ class QuickReplyManager final : public Actor { td_api::object_ptr get_quick_reply_shortcut_object(const Shortcut *s, const char *source) const; - td_api::object_ptr get_quick_reply_shortcuts_object(const char *source) const; - static int32 get_shortcut_message_count(const Shortcut *s); - void load_quick_reply_shortcuts(Promise> &&promise); + void load_quick_reply_shortcuts(Promise &&promise); void on_reload_quick_reply_shortcuts( Result> r_shortcuts); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 472dcab3a..a5e2913c7 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5759,9 +5759,9 @@ void Td::on_request(uint64 id, td_api::editMessageSchedulingState &request) { std::move(request.scheduling_state_), std::move(promise)); } -void Td::on_request(uint64 id, const td_api::getQuickReplyShortcuts &request) { +void Td::on_request(uint64 id, const td_api::loadQuickReplyShortcuts &request) { CHECK_IS_USER(); - CREATE_REQUEST_PROMISE(); + CREATE_OK_REQUEST_PROMISE(); quick_reply_manager_->get_quick_reply_shortcuts(std::move(promise)); } diff --git a/td/telegram/Td.h b/td/telegram/Td.h index c3e732cfb..dde5d7bbe 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -864,7 +864,7 @@ class Td final : public Actor { void on_request(uint64 id, td_api::editMessageSchedulingState &request); - void on_request(uint64 id, const td_api::getQuickReplyShortcuts &request); + void on_request(uint64 id, const td_api::loadQuickReplyShortcuts &request); void on_request(uint64 id, const td_api::getStory &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index f10ff30fd..03e5ab593 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4825,8 +4825,8 @@ class CliClient final : public Actor { get_args(args, chat_id, message_id, date); send_request(td_api::make_object(chat_id, message_id, as_message_scheduling_state(date))); - } else if (op == "gqrs") { - send_request(td_api::make_object()); + } else if (op == "lqrs") { + send_request(td_api::make_object()); } else if (op == "gftdi") { send_request(td_api::make_object()); } else if (op == "cft") {