diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index a8cf01fd2..37635d079 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3106,7 +3106,7 @@ updateMessageContent chat_id:int53 message_id:int53 new_content:MessageContent = //@description A message was edited. Changes in the message content will come in a separate updateMessageContent @chat_id Chat identifier @message_id Message identifier @edit_date Point in time (Unix timestamp) when the message was edited @reply_markup New message reply markup; may be null updateMessageEdited chat_id:int53 message_id:int53 edit_date:int32 reply_markup:ReplyMarkup = Update; -//@description The information about interactions with a message has changed @chat_id Chat identifier @message_id Message identifier @interaction_info New information about interactions with the message +//@description The information about interactions with a message has changed @chat_id Chat identifier @message_id Message identifier @interaction_info New information about interactions with the message; may be null updateMessageInteractionInfo chat_id:int53 message_id:int53 interaction_info:messageInteractionInfo = Update; //@description The message content was opened. Updates voice note messages to "listened", video note messages to "viewed" and starts the TTL timer for self-destructing messages @chat_id Chat identifier @message_id Message identifier diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index ba801852c..b04c7a0dd 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -9744,6 +9744,14 @@ void ContactsManager::on_get_chat_full(tl_object_ptr &&c } update_channel_full(channel, channel_id); + + if (linked_channel_id.is_valid()) { + auto linked_channel_full = get_channel_full_force(linked_channel_id, "on_get_chat_full"); + on_update_channel_full_linked_channel_id(linked_channel_full, linked_channel_id, channel_id); + if (linked_channel_full != nullptr) { + update_channel_full(linked_channel_full, linked_channel_id); + } + } } promise.set_value(Unit()); } @@ -11195,6 +11203,17 @@ ChannelId ContactsManager::get_linked_channel_id(ChannelId channel_id) const { void ContactsManager::on_update_channel_full_linked_channel_id(ChannelFull *channel_full, ChannelId channel_id, ChannelId linked_channel_id) { + auto old_linked_channel_id = get_linked_channel_id(channel_id); + LOG(INFO) << "Uplate linked channel in " << channel_id << " from " << old_linked_channel_id << " to " + << linked_channel_id; + + if (channel_full != nullptr && channel_full->linked_channel_id != linked_channel_id && + channel_full->linked_channel_id.is_valid()) { + get_channel_force(channel_full->linked_channel_id); + get_channel_full_force(channel_full->linked_channel_id, "on_update_channel_full_linked_channel_id 0"); + } + auto old_linked_linked_channel_id = get_linked_channel_id(linked_channel_id); + remove_linked_channel_id(channel_id); remove_linked_channel_id(linked_channel_id); if (channel_id.is_valid() && linked_channel_id.is_valid()) { @@ -11250,6 +11269,20 @@ void ContactsManager::on_update_channel_full_linked_channel_id(ChannelFull *chan c->is_changed = true; update_channel(c, channel_id); } + + if (old_linked_channel_id != linked_channel_id) { + // must be called after the linked channel is changed + td_->messages_manager_->on_dialog_linked_channel_updated(DialogId(channel_id), old_linked_channel_id, + linked_channel_id); + } + auto new_linked_linked_channel_id = get_linked_channel_id(linked_channel_id); + LOG(INFO) << "Uplate linked channel in " << linked_channel_id << " from " << old_linked_linked_channel_id << " to " + << new_linked_linked_channel_id; + if (old_linked_linked_channel_id != new_linked_linked_channel_id) { + // must be called after the linked channel is changed + td_->messages_manager_->on_dialog_linked_channel_updated(DialogId(linked_channel_id), old_linked_linked_channel_id, + new_linked_linked_channel_id); + } } void ContactsManager::on_update_channel_full_location(ChannelFull *channel_full, ChannelId channel_id, diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 1b548e6d6..a7ceea595 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -9645,6 +9645,22 @@ void MessagesManager::delete_dialog_history_from_server(DialogId dialog_id, Mess } } +void MessagesManager::find_discussed_messages(const Message *m, ChannelId old_channel_id, ChannelId new_channel_id, + vector &message_ids) { + if (m == nullptr) { + return; + } + + find_discussed_messages(m->left.get(), old_channel_id, new_channel_id, message_ids); + + if (!m->reply_info.is_empty() && m->reply_info.channel_id.is_valid() && + (m->reply_info.channel_id == old_channel_id || m->reply_info.channel_id == new_channel_id)) { + message_ids.push_back(m->message_id); + } + + find_discussed_messages(m->right.get(), old_channel_id, new_channel_id, message_ids); +} + void MessagesManager::find_messages_from_user(const Message *m, UserId user_id, vector &message_ids) { if (m == nullptr) { return; @@ -25449,6 +25465,7 @@ void MessagesManager::send_update_message_edited(DialogId dialog_id, const Messa } void MessagesManager::send_update_message_interaction_info(DialogId dialog_id, const Message *m) const { + CHECK(m != nullptr); if (td_->auth_manager_->is_bot()) { return; } @@ -26997,6 +27014,26 @@ void MessagesManager::on_dialog_user_is_deleted_updated(DialogId dialog_id, bool } } +void MessagesManager::on_dialog_linked_channel_updated(DialogId dialog_id, ChannelId old_linked_channel_id, + ChannelId new_linked_channel_id) const { + CHECK(dialog_id.get_type() == DialogType::Channel); + if (!is_broadcast_channel(dialog_id)) { + return; + } + auto d = get_dialog(dialog_id); // no need to create the dialog + if (d != nullptr && d->is_update_new_chat_sent) { + vector message_ids; + find_discussed_messages(d->messages.get(), old_linked_channel_id, new_linked_channel_id, message_ids); + LOG(INFO) << "Found discussion messages " << message_ids; + for (auto message_id : message_ids) { + send_update_message_interaction_info(dialog_id, get_message(d, message_id)); + if (message_id == d->last_message_id) { + send_update_chat_last_message_impl(d, "on_dialog_linked_channel_updated"); + } + } + } +} + DialogId MessagesManager::resolve_dialog_username(const string &username) const { auto cleaned_username = clean_username(username); auto it = resolved_usernames_.find(cleaned_username); @@ -29627,8 +29664,8 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq Message *top_m = get_message(d, m->top_reply_message_id); if (top_m != nullptr && is_active_message_reply_info(dialog_id, top_m->reply_info)) { top_m->reply_info.add_reply(m->sender_dialog_id.is_valid() ? m->sender_dialog_id : DialogId(m->sender_user_id)); - on_message_changed(d, top_m, true, "update_message_reply_count"); send_update_message_interaction_info(dialog_id, top_m); + on_message_changed(d, top_m, true, "update_message_reply_count"); } } } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 956b9f996..be15f8689 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -734,6 +734,9 @@ class MessagesManager : public Actor { void on_dialog_user_is_blocked_updated(DialogId dialog_id, bool is_blocked); void on_dialog_user_is_deleted_updated(DialogId dialog_id, bool is_deleted); + void on_dialog_linked_channel_updated(DialogId dialog_id, ChannelId old_linked_channel_id, + ChannelId new_linked_channel_id) const; + void on_resolved_username(const string &username, DialogId dialog_id); void drop_username(const string &username); @@ -1847,6 +1850,9 @@ class MessagesManager : public Actor { static MessageId find_message_by_date(const Message *m, int32 date); + static void find_discussed_messages(const Message *m, ChannelId old_channel_id, ChannelId new_channel_id, + vector &message_ids); + static void find_messages_from_user(const Message *m, UserId user_id, vector &message_ids); static void find_unread_mentions(const Message *m, vector &message_ids);