From 9ce2f7df4cb83e22f0e667426ac313c4a7058812 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 20 Jul 2023 16:30:46 +0300 Subject: [PATCH] Don't drop replies to deleted messages. --- telegram-bot-api/Client.cpp | 50 +++---------------------------------- telegram-bot-api/Client.h | 7 ------ 2 files changed, 3 insertions(+), 54 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 032c0b2..ac4e39b 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -194,7 +194,7 @@ Client::Client(td::ActorShared<> parent, const td::string &bot_token, bool is_te Client::~Client() { td::Scheduler::instance()->destroy_on_scheduler(SharedData::get_file_gc_scheduler_id(), messages_, users_, groups_, - supergroups_, chats_, reply_message_ids_, sticker_set_names_); + supergroups_, chats_, sticker_set_names_); } bool Client::init_methods() { @@ -4431,7 +4431,6 @@ void Client::on_get_callback_query_message(object_ptr message, } LOG(INFO) << "Can't find callback query reply to message " << message_info->reply_to_message_id << " in chat " << chat_id << ". It may be already deleted"; - message_info->reply_to_message_id = 0; } } else { LOG(INFO) << "Receive callback query " << (state == 1 ? "reply to " : "") << "message " << message_id << " in chat " @@ -11212,30 +11211,6 @@ void Client::drop_reply_to_message_in_another_chat(object_ptr & } } -void Client::set_message_reply_to_message_id(MessageInfo *message_info, int64 reply_to_message_id) { - if (message_info->reply_to_message_id == reply_to_message_id) { - return; - } - - if (message_info->reply_to_message_id > 0) { - LOG_IF(ERROR, reply_to_message_id > 0) - << "Message " << message_info->id << " in chat " << message_info->chat_id - << " has changed reply_to_message from " << message_info->reply_to_message_id << " to " << reply_to_message_id; - auto it = reply_message_ids_.find({message_info->chat_id, message_info->reply_to_message_id}); - if (it != reply_message_ids_.end()) { - it->second.erase(message_info->id); - if (it->second.empty()) { - reply_message_ids_.erase(it); - } - } - } - if (reply_to_message_id > 0) { - reply_message_ids_[{message_info->chat_id, reply_to_message_id}].insert(message_info->id); - } - - message_info->reply_to_message_id = reply_to_message_id; -} - td::Slice Client::get_sticker_type(const object_ptr &type) { CHECK(type != nullptr); switch (type->get_id()) { @@ -11487,26 +11462,7 @@ void Client::process_new_message_queue(int64 chat_id, int state) { new_message_queues_.erase(chat_id); } -void Client::remove_replies_to_message(int64 chat_id, int64 reply_to_message_id, bool only_from_cache) { - auto it = reply_message_ids_.find({chat_id, reply_to_message_id}); - if (it == reply_message_ids_.end()) { - return; - } - - if (!only_from_cache) { - for (auto message_id : it->second) { - auto message_info = get_message_editable(chat_id, message_id); - CHECK(message_info != nullptr); - CHECK(message_info->reply_to_message_id == reply_to_message_id); - message_info->reply_to_message_id = 0; - } - } - reply_message_ids_.erase(it); -} - td::unique_ptr Client::delete_message(int64 chat_id, int64 message_id, bool only_from_cache) { - remove_replies_to_message(chat_id, message_id, only_from_cache); - auto message_info = std::move(messages_[{chat_id, message_id}]); if (message_info == nullptr) { if (yet_unsent_messages_.count({chat_id, message_id}) > 0) { @@ -11533,7 +11489,6 @@ td::unique_ptr Client::delete_message(int64 chat_id, int64 on_message_send_failed(chat_id, message_id, 0, std::move(error)); } } else { - set_message_reply_to_message_id(message_info.get(), 0); messages_.erase({chat_id, message_id}); } return message_info; @@ -11643,7 +11598,8 @@ Client::FullMessageId Client::add_message(object_ptr &&message, drop_reply_to_message_in_another_chat(message); - set_message_reply_to_message_id(message_info.get(), message->reply_to_message_id_); + message_info->reply_to_message_id = message->reply_to_message_id_; + if (message_info->content == nullptr || force_update_content) { message_info->content = std::move(message->content_); message_info->is_content_changed = true; diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 682578d..3a2c278 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -837,8 +837,6 @@ class Client final : public WebhookActor::Callback { static void drop_reply_to_message_in_another_chat(object_ptr &message); - void set_message_reply_to_message_id(MessageInfo *message_info, int64 reply_to_message_id); - static td::Slice get_sticker_type(const object_ptr &type); static td::Result> get_sticker_type(td::Slice type); @@ -875,8 +873,6 @@ class Client final : public WebhookActor::Callback { static void json_store_permissions(td::JsonObjectScope &object, const td_api::chatPermissions *permissions); - void remove_replies_to_message(int64 chat_id, int64 reply_to_message_id, bool only_from_cache); - td::unique_ptr delete_message(int64 chat_id, int64 message_id, bool only_from_cache); void add_new_message(object_ptr &&message, bool is_edited); @@ -1037,9 +1033,6 @@ class Client final : public WebhookActor::Callback { td::WaitFreeHashMap> supergroups_; td::WaitFreeHashMap> chats_; - td::FlatHashMap, FullMessageIdHash> - reply_message_ids_; // message -> replies to it - td::FlatHashMap> file_download_listeners_; td::FlatHashSet download_started_file_ids_;