From e4ffed5752d5f513716ac421ac19852d0ac553e8 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 25 Oct 2023 16:46:17 +0300 Subject: [PATCH] Move other reply_to_message_id checks to ReplyHeader parsing. --- td/telegram/MessageReplyHeader.cpp | 20 +++++++++----- td/telegram/MessagesManager.cpp | 42 ------------------------------ td/telegram/MessagesManager.h | 5 ---- td/telegram/RepliedMessageInfo.cpp | 27 ++++++++++++++++++- 4 files changed, 39 insertions(+), 55 deletions(-) diff --git a/td/telegram/MessageReplyHeader.cpp b/td/telegram/MessageReplyHeader.cpp index eb4b5fdca..22e81fd19 100644 --- a/td/telegram/MessageReplyHeader.cpp +++ b/td/telegram/MessageReplyHeader.cpp @@ -48,13 +48,19 @@ MessageReplyHeader::MessageReplyHeader(Td *td, tl_object_ptr= message_id) { + LOG(ERROR) << "Receive top thread " << top_thread_message_id_ << " in " << message_id << " in " << dialog_id; + top_thread_message_id_ = MessageId(); } } } diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 81bebf90a..ff756c657 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -14448,9 +14448,6 @@ std::pair> MessagesManager::creat DialogId reply_in_dialog_id = reply_message_full_id.get_dialog_id(); MessageId top_thread_message_id = message_info.reply_header.top_thread_message_id_; bool is_topic_message = message_info.reply_header.is_topic_message_; - fix_server_reply_to_message_id(dialog_id, message_id, reply_in_dialog_id, reply_to_message_id); - fix_server_reply_to_message_id(dialog_id, message_id, reply_in_dialog_id, top_thread_message_id); - auto reply_to_story_full_id = message_info.reply_header.story_full_id_; if (reply_to_story_full_id != StoryFullId() && (dialog_type != DialogType::User || (reply_to_story_full_id.get_dialog_id() != my_dialog_id && @@ -24541,30 +24538,6 @@ MessageInputReplyTo MessagesManager::get_message_input_reply_to(const Message *m return m->input_reply_to; } -void MessagesManager::fix_server_reply_to_message_id(DialogId dialog_id, MessageId message_id, - DialogId reply_in_dialog_id, - MessageId &reply_to_message_id) const { - if (!reply_to_message_id.is_valid()) { - if (reply_to_message_id.is_valid_scheduled()) { - CHECK(message_id.is_scheduled()); - CHECK(reply_in_dialog_id == DialogId()); - if (message_id == reply_to_message_id) { - LOG(ERROR) << "Receive reply to " << reply_to_message_id << " for " << message_id << " in " << dialog_id; - reply_to_message_id = MessageId(); - } - return; - } - CHECK(reply_to_message_id == MessageId()); - return; - } - - if (!message_id.is_scheduled() && !reply_in_dialog_id.is_valid() && - ((reply_to_message_id > message_id && !has_qts_messages(dialog_id)) || reply_to_message_id == message_id)) { - LOG(ERROR) << "Receive reply to wrong " << reply_to_message_id << " in " << message_id << " in " << dialog_id; - reply_to_message_id = MessageId(); - } -} - vector MessagesManager::get_message_file_ids(const Message *m) const { CHECK(m != nullptr); return get_message_content_file_ids(m->content.get(), td_); @@ -26221,21 +26194,6 @@ void MessagesManager::do_send_inline_query_result_message(DialogId dialog_id, Me get_message_schedule_date(m), random_id, query_id, result_id); } -bool MessagesManager::has_qts_messages(DialogId dialog_id) const { - switch (dialog_id.get_type()) { - case DialogType::User: - case DialogType::Chat: - return td_->option_manager_->get_option_integer("session_count") > 1; - case DialogType::Channel: - case DialogType::SecretChat: - return false; - case DialogType::None: - default: - UNREACHABLE(); - return false; - } -} - bool MessagesManager::can_edit_message(DialogId dialog_id, const Message *m, bool is_editing, bool only_reply_markup) const { if (m == nullptr) { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index f72eb040b..eaac30e83 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1816,8 +1816,6 @@ class MessagesManager final : public Actor { bool can_edit_message(DialogId dialog_id, const Message *m, bool is_editing, bool only_reply_markup = false) const; - bool has_qts_messages(DialogId dialog_id) const; - bool can_report_dialog(DialogId dialog_id) const; Status can_pin_messages(DialogId dialog_id) const; @@ -1846,9 +1844,6 @@ class MessagesManager final : public Actor { static MessageInputReplyTo get_message_input_reply_to(const Message *m); - void fix_server_reply_to_message_id(DialogId dialog_id, MessageId message_id, DialogId reply_in_dialog_id, - MessageId &reply_to_message_id) const; - bool can_set_game_score(DialogId dialog_id, const Message *m) const; void add_postponed_channel_update(DialogId dialog_id, tl_object_ptr &&update, int32 new_pts, diff --git a/td/telegram/RepliedMessageInfo.cpp b/td/telegram/RepliedMessageInfo.cpp index 6e31f0ab4..750c01df7 100644 --- a/td/telegram/RepliedMessageInfo.cpp +++ b/td/telegram/RepliedMessageInfo.cpp @@ -7,21 +7,38 @@ #include "td/telegram/RepliedMessageInfo.h" #include "td/telegram/MessageFullId.h" +#include "td/telegram/OptionManager.h" #include "td/telegram/ScheduledServerMessageId.h" #include "td/telegram/ServerMessageId.h" #include "td/telegram/StoryId.h" +#include "td/telegram/Td.h" #include "td/telegram/UserId.h" #include "td/utils/logging.h" namespace td { +static bool has_qts_messages(const Td *td, DialogId dialog_id) { + switch (dialog_id.get_type()) { + case DialogType::User: + case DialogType::Chat: + return td->option_manager_->get_option_integer("session_count") > 1; + case DialogType::Channel: + case DialogType::SecretChat: + return false; + case DialogType::None: + default: + UNREACHABLE(); + return false; + } +} + RepliedMessageInfo::RepliedMessageInfo(Td *td, tl_object_ptr &&reply_header, DialogId dialog_id, MessageId message_id, int32 date) { CHECK(reply_header != nullptr); if (reply_header->reply_to_scheduled_) { message_id_ = MessageId(ScheduledServerMessageId(reply_header->reply_to_msg_id_), date); - if (message_id.is_scheduled()) { + if (message_id.is_valid_scheduled()) { auto reply_to_peer_id = std::move(reply_header->reply_to_peer_id_); if (reply_to_peer_id != nullptr) { dialog_id_ = DialogId(reply_to_peer_id); @@ -30,6 +47,10 @@ RepliedMessageInfo::RepliedMessageInfo(Td *td, tl_object_ptr message_id && !has_qts_messages(td, dialog_id)) || message_id_ == message_id)) { + LOG(ERROR) << "Receive reply to " << message_id_ << " in " << MessageFullId{dialog_id, message_id}; + message_id_ = MessageId(); } } else if (reply_header->reply_to_peer_id_ != nullptr) { LOG(ERROR) << "Receive " << to_string(reply_header) << " in " << MessageFullId{dialog_id, message_id};