diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 910d1b7d2..40e5a1ea5 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4172,9 +4172,10 @@ removeNotificationGroup notification_group_id:int32 max_notification_id:int32 = //@description Returns an HTTPS link to a message in a chat. Available only for already sent messages in supergroups and channels. This is an offline request //@chat_id Identifier of the chat to which the message belongs //@message_id Identifier of the message +//@media_timestamp If not 0, timestamp from which the video/audio/video note/voice note playing should start, in seconds //@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 for_album:Bool for_comment:Bool = MessageLink; +getMessageLink chat_id:int53 message_id:int53 media_timestamp:int32 for_album:Bool for_comment: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/MessageContentType.cpp b/td/telegram/MessageContentType.cpp index 35ff8c36a..036d3749b 100644 --- a/td/telegram/MessageContentType.cpp +++ b/td/telegram/MessageContentType.cpp @@ -336,8 +336,9 @@ bool can_have_message_content_caption(MessageContentType content_type) { } bool can_have_media_timestamp(MessageContentType content_type) { - return content_type == MessageContentType::Audio || content_type == MessageContentType::Video || - content_type == MessageContentType::VideoNote || content_type == MessageContentType::VoiceNote; + return content_type == MessageContentType::Audio || content_type == MessageContentType::Text || + content_type == MessageContentType::Video || content_type == MessageContentType::VideoNote || + content_type == MessageContentType::VoiceNote; } } // namespace td diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index a3ed3ae36..0a6f5950f 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -17276,8 +17276,8 @@ bool MessagesManager::is_message_edited_recently(FullMessageId full_message_id, return m->edit_date >= G()->unix_time() - seconds; } -Result> MessagesManager::get_message_link(FullMessageId full_message_id, bool for_group, - bool for_comment) { +Result> MessagesManager::get_message_link(FullMessageId full_message_id, int32 media_timestamp, + bool for_group, bool for_comment) { auto dialog_id = full_message_id.get_dialog_id(); auto d = get_dialog_force(dialog_id, "get_message_link"); if (d == nullptr) { @@ -17318,10 +17318,22 @@ Result> MessagesManager::get_message_link(FullMessageId for_comment = false; } + if (media_timestamp <= 0 || !can_have_media_timestamp(m->content->get_type())) { + media_timestamp = 0; + } + if (media_timestamp != 0) { + auto duration = get_message_content_duration(m->content.get(), td_); + if (duration != 0 && media_timestamp > duration) { + media_timestamp = 0; + } + } + td_->create_handler(Promise()) ->send(dialog_id.get_channel_id(), m->message_id, for_group, true); - auto t_me = G()->shared_config().get_option_string("t_me_url", "https://t.me/"); + SliceBuilder sb; + sb << G()->shared_config().get_option_string("t_me_url", "https://t.me/"); + if (for_comment) { 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)) { @@ -17335,38 +17347,49 @@ Result> MessagesManager::get_message_link(FullMessageId if (linked_m != nullptr && is_active_message_reply_info(linked_dialog_id, linked_m->reply_info) && linked_message_id.is_server() && have_input_peer(linked_dialog_id, AccessRights::Read) && !channel_username.empty()) { - return std::make_pair( - PSTRING() << t_me << channel_username << '/' << linked_message_id.get_server_message_id().get() - << "?comment=" << m->message_id.get_server_message_id().get() << (for_group ? "" : "&single"), - true); + sb << channel_username << '/' << linked_message_id.get_server_message_id().get() + << "?comment=" << m->message_id.get_server_message_id().get(); + if (!for_group) { + sb << "&single"; + } + if (media_timestamp > 0) { + sb << "&t=" << media_timestamp; + } + return std::make_pair(sb.as_cslice().str(), true); } } } auto dialog_username = td_->contacts_manager_->get_channel_username(dialog_id.get_channel_id()); - if (m->content->get_type() == MessageContentType::VideoNote && is_broadcast_channel(dialog_id) && - !dialog_username.empty()) { + bool is_public = !dialog_username.empty(); + if (m->content->get_type() == MessageContentType::VideoNote && is_broadcast_channel(dialog_id) && is_public) { return std::make_pair( PSTRING() << "https://telesco.pe/" << dialog_username << '/' << m->message_id.get_server_message_id().get(), true); } - string args; + if (is_public) { + sb << dialog_username; + } else { + sb << "c/" << dialog_id.get_channel_id().get(); + } + sb << '/' << m->message_id.get_server_message_id().get(); + + char separator = '?'; if (for_comment) { - args = PSTRING() << "?thread=" << m->top_thread_message_id.get_server_message_id().get(); + sb << separator << "thread=" << m->top_thread_message_id.get_server_message_id().get(); + separator = '&'; } if (!for_group) { - args += args.empty() ? '?' : '&'; - args += "single"; + sb << separator << "single"; + separator = '&'; + } + if (media_timestamp > 0) { + sb << separator << "t=" << media_timestamp; + separator = '&'; } - bool is_public = !dialog_username.empty(); - if (!is_public) { - dialog_username = PSTRING() << "c/" << dialog_id.get_channel_id().get(); - } - return std::make_pair(PSTRING() << G()->shared_config().get_option_string("t_me_url", "https://t.me/") - << dialog_username << '/' << m->message_id.get_server_message_id().get() << args, - is_public); + return std::make_pair(sb.as_cslice().str(), is_public); } string MessagesManager::get_message_embedding_code(FullMessageId full_message_id, bool for_group, diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 009bedd47..e55736511 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -576,7 +576,8 @@ class MessagesManager final : public Actor { bool is_message_edited_recently(FullMessageId full_message_id, int32 seconds); - Result> get_message_link(FullMessageId full_message_id, bool for_group, bool for_comment); + Result> get_message_link(FullMessageId full_message_id, int32 media_timestamp, bool for_group, + bool for_comment); 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 ca869f1c4..15e35236c 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5124,8 +5124,9 @@ void Td::on_request(uint64 id, const td_api::getMessageThread &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.for_album_, request.for_comment_); + 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_); if (r_message_link.is_error()) { send_closure(actor_id(this), &Td::send_error, id, r_message_link.move_as_error()); } else { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 6f5c4a675..995e774d8 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2604,11 +2604,12 @@ class CliClient final : public Actor { } else if (op == "gmlink") { string chat_id; string message_id; + int32 media_timestamp; bool for_album; bool for_comment; - get_args(args, chat_id, message_id, for_album, for_comment); + get_args(args, chat_id, message_id, media_timestamp, for_album, for_comment); send_request(td_api::make_object(as_chat_id(chat_id), as_message_id(message_id), - for_album, for_comment)); + media_timestamp, for_album, for_comment)); } else if (op == "gmec") { string chat_id; string message_id;