diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index fdb6ba92f..7e724d13a 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7787,6 +7787,11 @@ reorderQuickReplyShortcuts shortcut_ids:vector = Ok; //@shortcut_id Unique identifier of the quick reply shortcut loadQuickReplyShortcutMessages shortcut_id:int32 = Ok; +//@description Deletes specified quick reply messages +//@shortcut_id Unique identifier of the quick reply shortcut to which the messages belong +//@message_ids Unique identifiers of the messages +deleteQuickReplyShortcutMessages shortcut_id:int32 message_ids:vector = Ok; + //@description Returns list of custom emojis, which can be used as forum topic icon by all users getForumTopicDefaultIcons = Stickers; diff --git a/td/telegram/QuickReplyManager.cpp b/td/telegram/QuickReplyManager.cpp index ec8debd5d..e611770dd 100644 --- a/td/telegram/QuickReplyManager.cpp +++ b/td/telegram/QuickReplyManager.cpp @@ -148,6 +148,36 @@ class GetQuickReplyMessagesQuery final : public Td::ResultHandler { } }; +class DeleteQuickReplyMessagesQuery final : public Td::ResultHandler { + Promise promise_; + QuickReplyShortcutId shortcut_id_; + + public: + explicit DeleteQuickReplyMessagesQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(QuickReplyShortcutId shortcut_id, const vector &message_ids) { + shortcut_id_ = shortcut_id; + send_query(G()->net_query_creator().create(telegram_api::messages_deleteQuickReplyMessages( + shortcut_id.get(), MessageId::get_server_message_ids(message_ids)), + {{"me"}})); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + promise_.set_value(Unit()); + } + + void on_error(Status status) final { + td_->quick_reply_manager_->reload_quick_reply_messages(shortcut_id_, Promise()); + promise_.set_error(std::move(status)); + } +}; + QuickReplyManager::QuickReplyMessage::~QuickReplyMessage() = default; template @@ -933,6 +963,40 @@ void QuickReplyManager::delete_quick_reply_messages(Shortcut *s, const vector &message_ids, + Promise &&promise) { + auto s = get_shortcut(shortcut_id); + if (s == nullptr) { + return promise.set_error(Status::Error(400, "Shortcut not found")); + } + if (message_ids.empty()) { + return promise.set_value(Unit()); + } + + vector deleted_server_message_ids; + for (auto &message_id : message_ids) { + if (!message_id.is_valid()) { + return promise.set_error(Status::Error(400, "Invalid message identifier")); + } + + // message_id = get_persistent_message_id(s, message_id); + if (message_id.is_server()) { + deleted_server_message_ids.push_back(message_id); + } + } + + delete_quick_reply_messages_on_server(shortcut_id, std::move(deleted_server_message_ids), std::move(promise)); + + delete_quick_reply_messages(s, message_ids); +} + +void QuickReplyManager::delete_quick_reply_messages_on_server(QuickReplyShortcutId shortcut_id, + const vector &message_ids, + Promise &&promise) { + td_->create_handler(std::move(promise))->send(shortcut_id, message_ids); +} + void QuickReplyManager::get_quick_reply_shortcut_messages(QuickReplyShortcutId shortcut_id, Promise &&promise) { auto s = get_shortcut(shortcut_id); if (s == nullptr) { diff --git a/td/telegram/QuickReplyManager.h b/td/telegram/QuickReplyManager.h index 9d5d29255..aa7688066 100644 --- a/td/telegram/QuickReplyManager.h +++ b/td/telegram/QuickReplyManager.h @@ -46,8 +46,13 @@ class QuickReplyManager final : public Actor { void get_quick_reply_shortcut_messages(QuickReplyShortcutId shortcut_id, Promise &&promise); + void delete_quick_reply_shortcut_messages(QuickReplyShortcutId shortcut_id, const vector &message_ids, + Promise &&promise); + void reload_quick_reply_shortcuts(); + void reload_quick_reply_messages(QuickReplyShortcutId shortcut_id, Promise &&promise); + void reload_quick_reply_message(QuickReplyShortcutId shortcut_id, MessageId message_id, Promise &&promise); FileSourceId get_quick_reply_message_file_source_id(QuickReplyMessageFullId message_full_id); @@ -175,8 +180,6 @@ class QuickReplyManager final : public Actor { int64 get_shortcuts_hash() const; - void reload_quick_reply_messages(QuickReplyShortcutId shortcut_id, Promise &&promise); - void on_reload_quick_reply_messages(QuickReplyShortcutId shortcut_id, Result> r_messages); @@ -246,6 +249,9 @@ class QuickReplyManager final : public Actor { void reorder_quick_reply_shortcuts_on_server(vector shortcut_ids, Promise &&promise); + void delete_quick_reply_messages_on_server(QuickReplyShortcutId shortcut_id, const vector &message_ids, + Promise &&promise); + string get_quick_reply_shortcuts_database_key(); void save_quick_reply_shortcuts(); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index b780caa31..204d1e8f1 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5787,6 +5787,13 @@ void Td::on_request(uint64 id, const td_api::loadQuickReplyShortcutMessages &req std::move(promise)); } +void Td::on_request(uint64 id, const td_api::deleteQuickReplyShortcutMessages &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + quick_reply_manager_->delete_quick_reply_shortcut_messages( + QuickReplyShortcutId(request.shortcut_id_), MessageId::get_message_ids(request.message_ids_), std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::getStory &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index e2b3d72ac..6fe175e11 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -872,6 +872,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::loadQuickReplyShortcutMessages &request); + void on_request(uint64 id, const td_api::deleteQuickReplyShortcutMessages &request); + void on_request(uint64 id, const td_api::getStory &request); void on_request(uint64 id, const td_api::getChatsToSendStories &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 863193768..e9d5d0714 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4859,6 +4859,12 @@ class CliClient final : public Actor { ShortcutId shortcut_id; get_args(args, shortcut_id); send_request(td_api::make_object(shortcut_id)); + } else if (op == "dqrsm") { + ShortcutId shortcut_id; + string message_ids; + get_args(args, shortcut_id, message_ids); + send_request( + td_api::make_object(shortcut_id, as_message_ids(message_ids))); } else if (op == "gftdi") { send_request(td_api::make_object()); } else if (op == "cft") {