From ff0c205fe9f41e7d5b9c6a6bfabb8c74dda9a6fa Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 4 Nov 2022 15:56:16 +0300 Subject: [PATCH] Generate new links for topic messages. --- td/generate/scheme/td_api.tl | 4 ++-- td/telegram/MessagesManager.cpp | 26 ++++++++++++++------------ td/telegram/MessagesManager.h | 2 +- td/telegram/Td.cpp | 2 +- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index ebd814611..46b00ebdc 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -5114,8 +5114,8 @@ removeNotificationGroup notification_group_id:int32 max_notification_id:int32 = //@message_id Identifier of the message //@media_timestamp If not 0, timestamp from which the video/audio/video note/voice note playing must start, in seconds. The media can be in the message content or in its web page preview //@for_album Pass true to create a link for the whole media album -//@for_comment Pass true to create a link to the message as a channel post comment, or from a message thread -getMessageLink chat_id:int53 message_id:int53 media_timestamp:int32 for_album:Bool for_comment:Bool = MessageLink; +//@in_message_thread Pass true to create a link to the message as a channel post comment, in a message thread, or a forum topic +getMessageLink chat_id:int53 message_id:int53 media_timestamp:int32 for_album:Bool in_message_thread:Bool = MessageLink; //@description Returns an HTML code for embedding the message. Available only for messages in supergroups and channels with a username //@chat_id Identifier of the chat to which the message belongs diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 1aac20086..4ca87654d 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -19212,7 +19212,7 @@ bool MessagesManager::can_report_message_reactions(DialogId dialog_id, const Mes } Result> MessagesManager::get_message_link(FullMessageId full_message_id, int32 media_timestamp, - bool for_group, bool for_comment) { + bool for_group, bool in_message_thread) { auto dialog_id = full_message_id.get_dialog_id(); auto d = get_dialog_force(dialog_id, "get_message_link"); if (d == nullptr) { @@ -19244,7 +19244,7 @@ Result> MessagesManager::get_message_link(FullMessageId dialog_id = m->forward_info->sender_dialog_id; message_id = m->forward_info->message_id; for_group = false; - for_comment = false; + in_message_thread = false; auto channel_message = get_message({dialog_id, message_id}); if (channel_message != nullptr && channel_message->media_album_id == 0) { for_group = true; // default is true @@ -19255,14 +19255,9 @@ Result> MessagesManager::get_message_link(FullMessageId } } - if (!m->top_thread_message_id.is_valid() || !m->top_thread_message_id.is_server()) { - for_comment = false; - } - if (is_deleted_message(d, m->top_thread_message_id)) { - for_comment = false; - } - if (for_comment && is_broadcast_channel(dialog_id)) { - for_comment = false; + if (!m->top_thread_message_id.is_valid() || !m->top_thread_message_id.is_server() || + is_deleted_message(d, m->top_thread_message_id) || is_broadcast_channel(dialog_id)) { + in_message_thread = false; } if (!td_->auth_manager_->is_bot()) { @@ -19273,7 +19268,8 @@ Result> MessagesManager::get_message_link(FullMessageId SliceBuilder sb; sb << td_->option_manager_->get_option_string("t_me_url", "https://t.me/"); - if (for_comment) { + if (in_message_thread) { + // try to generate a comment link auto *top_m = get_message_force(d, m->top_thread_message_id, "get_public_message_link"); if (is_discussion_message(dialog_id, top_m) && is_active_message_reply_info(dialog_id, top_m->reply_info)) { auto linked_dialog_id = top_m->forward_info->from_dialog_id; @@ -19311,10 +19307,16 @@ Result> MessagesManager::get_message_link(FullMessageId } else { sb << "c/" << dialog_id.get_channel_id().get(); } + if (in_message_thread && td_->contacts_manager_->is_forum_channel(dialog_id.get_channel_id())) { + if (m->top_thread_message_id != message_id) { + sb << '/' << m->top_thread_message_id.get_server_message_id().get(); + } + in_message_thread = false; + } sb << '/' << message_id.get_server_message_id().get(); char separator = '?'; - if (for_comment) { + if (in_message_thread) { sb << separator << "thread=" << m->top_thread_message_id.get_server_message_id().get(); separator = '&'; } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 55241f613..888a3dd9f 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -661,7 +661,7 @@ class MessagesManager final : public Actor { bool is_deleted_secret_chat(DialogId dialog_id) const; Result> get_message_link(FullMessageId full_message_id, int32 media_timestamp, bool for_group, - bool for_comment); + bool in_message_thread); string get_message_embedding_code(FullMessageId full_message_id, bool for_group, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index fc431d320..20531f4a2 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -4668,7 +4668,7 @@ void Td::on_request(uint64 id, const td_api::getMessageViewers &request) { void Td::on_request(uint64 id, const td_api::getMessageLink &request) { auto r_message_link = messages_manager_->get_message_link({DialogId(request.chat_id_), MessageId(request.message_id_)}, - request.media_timestamp_, request.for_album_, request.for_comment_); + request.media_timestamp_, request.for_album_, request.in_message_thread_); if (r_message_link.is_error()) { send_closure(actor_id(this), &Td::send_error, id, r_message_link.move_as_error()); } else {