diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index cf7f98084..ba801852c 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -13029,6 +13029,14 @@ bool ContactsManager::get_channel_has_linked_channel(const Channel *c) { return c->has_linked_channel; } +ChannelId ContactsManager::get_channel_linked_channel_id(ChannelId channel_id) { + auto channel_full = get_channel_full_force(channel_id, "get_channel_linked_channel_id"); + if (channel_full == nullptr) { + return ChannelId(); + } + return channel_full->linked_channel_id; +} + int32 ContactsManager::get_channel_slow_mode_delay(ChannelId channel_id) { auto channel_full = get_channel_full_force(channel_id, "get_channel_slow_mode_delay"); if (channel_full == nullptr) { diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 3c649d881..38c169f1d 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -493,6 +493,7 @@ class ContactsManager : public Actor { int32 get_channel_participant_count(ChannelId channel_id) const; bool get_channel_sign_messages(ChannelId channel_id) const; bool get_channel_has_linked_channel(ChannelId channel_id) const; + ChannelId get_channel_linked_channel_id(ChannelId channel_id); int32 get_channel_slow_mode_delay(ChannelId channel_id); std::pair> search_among_users(const vector &user_ids, const string &query, int32 limit); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 690d46426..10384129f 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -6140,9 +6140,38 @@ void MessagesManager::update_message_interaction_info(FullMessageId full_message } } +bool MessagesManager::is_active_message_reply_info(DialogId dialog_id, const MessageReplyInfo &info) const { + if (info.is_empty()) { + return false; + } + if (dialog_id.get_type() != DialogType::Channel) { + return false; + } + if (!info.is_comment) { + return true; + } + if (!is_broadcast_channel(dialog_id)) { + return true; + } + + auto channel_id = dialog_id.get_channel_id(); + if (!td_->contacts_manager_->get_channel_has_linked_channel(channel_id)) { + return false; + } + auto linked_channel_id = td_->contacts_manager_->get_channel_linked_channel_id(channel_id); + if (!linked_channel_id.is_valid()) { + // keep the comment button while linked channel is unknown + td_->contacts_manager_->get_channel_full(channel_id, true, Auto()); + return true; + } + + return linked_channel_id == info.channel_id; +} + td_api::object_ptr MessagesManager::get_message_interaction_info_object( DialogId dialog_id, const Message *m) const { - if (m->view_count == 0 && m->forward_count == 0 && m->reply_info.is_empty()) { + bool is_active_reply_info = is_active_message_reply_info(dialog_id, m->reply_info); + if (m->view_count == 0 && m->forward_count == 0 && !is_active_reply_info) { return nullptr; } if (m->message_id.is_scheduled() && (m->forward_info == nullptr || is_broadcast_channel(dialog_id))) { @@ -6152,14 +6181,19 @@ td_api::object_ptr MessagesManager::get_message_ return nullptr; } + int32 reply_count = -1; vector recent_replier_user_ids; - for (auto recent_replier_dialog_id : m->reply_info.recent_replier_dialog_ids) { - if (dialog_id.get_type() == DialogType::User) { - recent_replier_user_ids.push_back(recent_replier_dialog_id.get_user_id()); + if (is_active_reply_info) { + reply_count = m->reply_info.reply_count; + for (auto recent_replier_dialog_id : m->reply_info.recent_replier_dialog_ids) { + if (dialog_id.get_type() == DialogType::User) { + recent_replier_user_ids.push_back(recent_replier_dialog_id.get_user_id()); + } } } + return td_api::make_object( - m->view_count, m->forward_count, m->reply_info.reply_count, + m->view_count, m->forward_count, reply_count, td_->contacts_manager_->get_user_ids_object(recent_replier_user_ids, "get_message_interaction_info_object")); } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 14c67d5a3..b31df7c69 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1858,6 +1858,8 @@ class MessagesManager : public Actor { void update_message_interaction_info(FullMessageId full_message_id, int32 view_count, int32 forward_count, bool has_reply_info, tl_object_ptr &&reply_info); + bool is_active_message_reply_info(DialogId dialog_id, const MessageReplyInfo &info) const; + td_api::object_ptr get_message_interaction_info_object(DialogId dialog_id, const Message *m) const;