diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index b60545af1..963eec30e 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3685,14 +3685,16 @@ removeNotificationGroup notification_group_id:int32 max_notification_id:int32 = //@description Returns a public HTTPS link to a message. Available only for messages in supergroups and channels with a username //@chat_id Identifier of the chat to which the message belongs //@message_id Identifier of the message -//@for_album Pass true to create a link for a whole media album -//@for_comment Pass true to create a link to a message as a channel post comment. The channel or the discussion supergroup must have a username +//@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. The channel or the discussion supergroup must have a username getPublicMessageLink chat_id:int53 message_id:int53 for_album:Bool for_comment:Bool = PublicMessageLink; //@description Returns a private HTTPS link to a message in a chat. Available only for already sent messages in supergroups and channels. The link will work only for members of the chat //@chat_id Identifier of the chat to which the message belongs //@message_id Identifier of the message -getMessageLink chat_id:int53 message_id:int53 = HttpUrl; +//@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 +getMessageLink chat_id:int53 message_id:int53 for_album:Bool for_comment:Bool = HttpUrl; //@description Returns information about a public or private message link @url The message link in the format "https://t.me/c/...", or "tg://privatepost?...", or "https://t.me/username/...", or "tg://resolve?..." getMessageLinkInfo url:string = MessageLinkInfo; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 86306049a..02fd0dea4 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 1cac98c22..dc898c51a 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -15915,7 +15915,8 @@ void MessagesManager::on_get_public_message_link(FullMessageId full_message_id, std::move(url), std::move(html)}; } -string MessagesManager::get_message_link(FullMessageId full_message_id, Promise &&promise) { +string MessagesManager::get_message_link(FullMessageId full_message_id, bool for_group, bool for_comment, + Promise &&promise) { auto dialog_id = full_message_id.get_dialog_id(); auto d = get_dialog_force(dialog_id); if (d == nullptr) { @@ -15946,12 +15947,33 @@ string MessagesManager::get_message_link(FullMessageId full_message_id, Promise< return {}; } + if (m->media_album_id == 0) { + for_group = true; // default is true + } + + if (!m->top_reply_message_id.is_valid() || !m->top_reply_message_id.is_server()) { + for_comment = false; + } + if (d->deleted_message_ids.count(m->top_reply_message_id) != 0) { + for_comment = false; + } + td_->create_handler(Promise()) - ->send(dialog_id.get_channel_id(), m->message_id, false, true); + ->send(dialog_id.get_channel_id(), m->message_id, for_group, true); promise.set_value(Unit()); + + string args; + if (for_comment) { + args = PSTRING() << "?thread=" << m->top_reply_message_id.get_server_message_id().get(); + } + if (!for_group) { + args += args.empty() ? '?' : '&'; + args += "single"; + } + return PSTRING() << G()->shared_config().get_option_string("t_me_url", "https://t.me/") << "c/" - << dialog_id.get_channel_id().get() << "/" << m->message_id.get_server_message_id().get(); + << dialog_id.get_channel_id().get() << "/" << m->message_id.get_server_message_id().get() << args; } Result MessagesManager::get_message_link_info(Slice url) { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index cf1311af5..bb9a019e1 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -579,7 +579,7 @@ class MessagesManager : public Actor { void on_get_public_message_link(FullMessageId full_message_id, bool for_group, string url, string html); - string get_message_link(FullMessageId full_message_id, Promise &&promise); + string get_message_link(FullMessageId full_message_id, bool for_group, bool for_comment, Promise &&promise); struct MessageLinkInfo { string username; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index dbd4c4002..f8a3aec8c 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -1142,11 +1142,13 @@ class GetPublicMessageLinkRequest : public RequestActor<> { class GetMessageLinkRequest : public RequestActor<> { FullMessageId full_message_id_; + bool for_group_; + bool for_comment_; string link_; void do_run(Promise &&promise) override { - link_ = td->messages_manager_->get_message_link(full_message_id_, std::move(promise)); + link_ = td->messages_manager_->get_message_link(full_message_id_, for_group_, for_comment_, std::move(promise)); } void do_send_result() override { @@ -1154,8 +1156,12 @@ class GetMessageLinkRequest : public RequestActor<> { } public: - GetMessageLinkRequest(ActorShared td, uint64 request_id, int64 dialog_id, int64 message_id) - : RequestActor(std::move(td), request_id), full_message_id_(DialogId(dialog_id), MessageId(message_id)) { + GetMessageLinkRequest(ActorShared td, uint64 request_id, int64 dialog_id, int64 message_id, bool for_group, + bool for_comment) + : RequestActor(std::move(td), request_id) + , full_message_id_(DialogId(dialog_id), MessageId(message_id)) + , for_group_(for_group) + , for_comment_(for_comment) { } }; @@ -5137,7 +5143,8 @@ void Td::on_request(uint64 id, const td_api::getPublicMessageLink &request) { void Td::on_request(uint64 id, const td_api::getMessageLink &request) { CHECK_IS_USER(); - CREATE_REQUEST(GetMessageLinkRequest, request.chat_id_, request.message_id_); + CREATE_REQUEST(GetMessageLinkRequest, request.chat_id_, request.message_id_, request.for_album_, + request.for_comment_); } void Td::on_request(uint64 id, td_api::getMessageLinkInfo &request) { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 60047aafb..3c3f4f6f4 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2630,8 +2630,13 @@ class CliClient final : public Actor { } else if (op == "gmlink") { string chat_id; string message_id; - std::tie(chat_id, message_id) = split(args); - send_request(td_api::make_object(as_chat_id(chat_id), as_message_id(message_id))); + string for_album; + string for_comment; + std::tie(chat_id, args) = split(args); + std::tie(message_id, args) = split(args); + std::tie(for_album, for_comment) = split(args); + send_request(td_api::make_object(as_chat_id(chat_id), as_message_id(message_id), + as_bool(for_album), as_bool(for_comment))); } else if (op == "gmli") { send_request(td_api::make_object(args)); } else if (op == "gcmbd") {