Add message.can_get_media_timestamp_links.

This commit is contained in:
levlam 2021-08-04 07:57:27 +03:00
parent 45bf232417
commit 304280df69
4 changed files with 62 additions and 30 deletions

View File

@ -759,6 +759,7 @@ messageSendingStateFailed error_code:int32 error_message:string can_retry:Bool r
//@can_be_deleted_for_all_users True, if the message can be deleted for all users //@can_be_deleted_for_all_users True, if the message can be deleted for all users
//@can_get_statistics True, if the message statistics are available //@can_get_statistics True, if the message statistics are available
//@can_get_message_thread True, if the message thread info is available //@can_get_message_thread True, if the message thread info is available
//@can_get_media_timestamp_links True, if media timestamp links can be generated for media timestamp entities in the message text, caption or web page description
//@is_channel_post True, if the message is a channel post. All messages to channels are channel posts, all other messages are not channel posts //@is_channel_post True, if the message is a channel post. All messages to channels are channel posts, all other messages are not channel posts
//@contains_unread_mention True, if the message contains an unread mention for the current user //@contains_unread_mention True, if the message contains an unread mention for the current user
//@date Point in time (Unix timestamp) when the message was sent //@date Point in time (Unix timestamp) when the message was sent
@ -776,7 +777,7 @@ messageSendingStateFailed error_code:int32 error_message:string can_retry:Bool r
//@restriction_reason If non-empty, contains a human-readable description of the reason why access to this message must be restricted //@restriction_reason If non-empty, contains a human-readable description of the reason why access to this message must be restricted
//@content Content of the message //@content Content of the message
//@reply_markup Reply markup for the message; may be null //@reply_markup Reply markup for the message; may be null
message id:int53 sender:MessageSender chat_id:int53 sending_state:MessageSendingState scheduling_state:MessageSchedulingState is_outgoing:Bool is_pinned:Bool can_be_edited:Bool can_be_forwarded:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_get_statistics:Bool can_get_message_thread:Bool is_channel_post:Bool contains_unread_mention:Bool date:int32 edit_date:int32 forward_info:messageForwardInfo interaction_info:messageInteractionInfo reply_in_chat_id:int53 reply_to_message_id:int53 message_thread_id:int53 ttl:int32 ttl_expires_in:double via_bot_user_id:int32 author_signature:string media_album_id:int64 restriction_reason:string content:MessageContent reply_markup:ReplyMarkup = Message; message id:int53 sender:MessageSender chat_id:int53 sending_state:MessageSendingState scheduling_state:MessageSchedulingState is_outgoing:Bool is_pinned:Bool can_be_edited:Bool can_be_forwarded:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_get_statistics:Bool can_get_message_thread:Bool can_get_media_timestamp_links:Bool is_channel_post:Bool contains_unread_mention:Bool date:int32 edit_date:int32 forward_info:messageForwardInfo interaction_info:messageInteractionInfo reply_in_chat_id:int53 reply_to_message_id:int53 message_thread_id:int53 ttl:int32 ttl_expires_in:double via_bot_user_id:int32 author_signature:string media_album_id:int64 restriction_reason:string content:MessageContent reply_markup:ReplyMarkup = Message;
//@description Contains a list of messages @total_count Approximate total count of messages found @messages List of messages; messages may be null //@description Contains a list of messages @total_count Approximate total count of messages found @messages List of messages; messages may be null
messages total_count:int32 messages:vector<message> = Messages; messages total_count:int32 messages:vector<message> = Messages;
@ -4172,7 +4173,7 @@ removeNotification notification_group_id:int32 notification_id:int32 = Ok;
removeNotificationGroup notification_group_id:int32 max_notification_id:int32 = Ok; removeNotificationGroup notification_group_id:int32 max_notification_id:int32 = Ok;
//@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 //@description Returns an HTTPS link to a message in a chat. Available only for already sent messages in supergroups and channels, or if message.can_get_media_timestamp_links and a media timestamp link is generated. This is an offline request
//@chat_id Identifier of the chat to which the message belongs //@chat_id Identifier of the chat to which the message belongs
//@message_id Identifier of the message //@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. The media can be in the message content or in its web page preview //@media_timestamp If not 0, timestamp from which the video/audio/video note/voice note playing should start, in seconds. The media can be in the message content or in its web page preview

View File

@ -696,7 +696,9 @@ class ExportChannelMessageLinkQuery final : public Td::ResultHandler {
for_group_ = for_group; for_group_ = for_group;
ignore_result_ = ignore_result; ignore_result_ = ignore_result;
auto input_channel = td->contacts_manager_->get_input_channel(channel_id); auto input_channel = td->contacts_manager_->get_input_channel(channel_id);
CHECK(input_channel != nullptr); if (input_channel == nullptr) {
return on_error(0, Status::Error(400, "Can't access the chat"));
}
int32 flags = 0; int32 flags = 0;
if (for_group) { if (for_group) {
flags |= telegram_api::channels_exportMessageLink::GROUPED_MASK; flags |= telegram_api::channels_exportMessageLink::GROUPED_MASK;
@ -17294,6 +17296,35 @@ bool MessagesManager::is_message_edited_recently(FullMessageId full_message_id,
return m->edit_date >= G()->unix_time() - seconds; return m->edit_date >= G()->unix_time() - seconds;
} }
Status MessagesManager::can_get_media_timestamp_link(DialogId dialog_id, const Message *m) {
if (m == nullptr) {
return Status::Error(400, "Message not found");
}
if (dialog_id.get_type() != DialogType::Channel) {
auto forward_info = m->forward_info.get();
if (!can_message_content_have_media_timestamp(m->content.get()) || forward_info == nullptr ||
forward_info->is_imported || is_forward_info_sender_hidden(forward_info) ||
!forward_info->message_id.is_valid() || !m->forward_info->message_id.is_server() ||
!forward_info->sender_dialog_id.is_valid() ||
forward_info->sender_dialog_id.get_type() != DialogType::Channel) {
return Status::Error(400, "Message links are available only for messages in supergroups and channel chats");
}
return Status::OK();
}
if (m->message_id.is_yet_unsent()) {
return Status::Error(400, "Message is not sent yet");
}
if (m->message_id.is_scheduled()) {
return Status::Error(400, "Message is scheduled");
}
if (!m->message_id.is_server()) {
return Status::Error(400, "Message is local");
}
return Status::OK();
}
Result<std::pair<string, bool>> MessagesManager::get_message_link(FullMessageId full_message_id, int32 media_timestamp, Result<std::pair<string, bool>> MessagesManager::get_message_link(FullMessageId full_message_id, int32 media_timestamp,
bool for_group, bool for_comment) { bool for_group, bool for_comment) {
auto dialog_id = full_message_id.get_dialog_id(); auto dialog_id = full_message_id.get_dialog_id();
@ -17304,26 +17335,23 @@ Result<std::pair<string, bool>> MessagesManager::get_message_link(FullMessageId
if (!have_input_peer(dialog_id, AccessRights::Read)) { if (!have_input_peer(dialog_id, AccessRights::Read)) {
return Status::Error(400, "Can't access the chat"); return Status::Error(400, "Can't access the chat");
} }
if (dialog_id.get_type() != DialogType::Channel) {
return Status::Error(400, "Public message links are available only for messages in supergroups and channel chats");
}
auto *m = get_message_force(d, full_message_id.get_message_id(), "get_message_link"); auto *m = get_message_force(d, full_message_id.get_message_id(), "get_message_link");
if (m == nullptr) { TRY_STATUS(can_get_media_timestamp_link(dialog_id, m));
return Status::Error(400, "Message not found"); auto message_id = m->message_id;
} if (dialog_id.get_type() != DialogType::Channel) {
if (m->message_id.is_yet_unsent()) { CHECK(m != nullptr);
return Status::Error(400, "Message is not sent yet"); CHECK(m->forward_info != nullptr);
} CHECK(m->forward_info->sender_dialog_id.get_type() == DialogType::Channel);
if (m->message_id.is_scheduled()) {
return Status::Error(400, "Message is scheduled");
}
if (!m->message_id.is_server()) {
return Status::Error(400, "Message is local");
}
if (m->media_album_id == 0) { dialog_id = m->forward_info->sender_dialog_id;
for_group = true; // default is true message_id = m->forward_info->message_id;
for_group = false;
for_comment = false;
} else {
if (m->media_album_id == 0) {
for_group = true; // default is true
}
} }
if (!m->top_thread_message_id.is_valid() || !m->top_thread_message_id.is_server()) { if (!m->top_thread_message_id.is_valid() || !m->top_thread_message_id.is_server()) {
@ -17340,6 +17368,7 @@ Result<std::pair<string, bool>> MessagesManager::get_message_link(FullMessageId
media_timestamp = 0; media_timestamp = 0;
} }
if (media_timestamp != 0) { if (media_timestamp != 0) {
for_group = false;
auto duration = get_message_content_duration(m->content.get(), td_); auto duration = get_message_content_duration(m->content.get(), td_);
if (duration != 0 && media_timestamp > duration) { if (duration != 0 && media_timestamp > duration) {
media_timestamp = 0; media_timestamp = 0;
@ -17348,7 +17377,7 @@ Result<std::pair<string, bool>> MessagesManager::get_message_link(FullMessageId
if (!td_->auth_manager_->is_bot()) { if (!td_->auth_manager_->is_bot()) {
td_->create_handler<ExportChannelMessageLinkQuery>(Promise<Unit>()) td_->create_handler<ExportChannelMessageLinkQuery>(Promise<Unit>())
->send(dialog_id.get_channel_id(), m->message_id, for_group, true); ->send(dialog_id.get_channel_id(), message_id, for_group, true);
} }
SliceBuilder sb; SliceBuilder sb;
@ -17368,7 +17397,7 @@ Result<std::pair<string, bool>> MessagesManager::get_message_link(FullMessageId
linked_message_id.is_server() && have_input_peer(linked_dialog_id, AccessRights::Read) && linked_message_id.is_server() && have_input_peer(linked_dialog_id, AccessRights::Read) &&
!channel_username.empty()) { !channel_username.empty()) {
sb << channel_username << '/' << linked_message_id.get_server_message_id().get() sb << channel_username << '/' << linked_message_id.get_server_message_id().get()
<< "?comment=" << m->message_id.get_server_message_id().get(); << "?comment=" << message_id.get_server_message_id().get();
if (!for_group) { if (!for_group) {
sb << "&single"; sb << "&single";
} }
@ -17384,8 +17413,7 @@ Result<std::pair<string, bool>> MessagesManager::get_message_link(FullMessageId
bool is_public = !dialog_username.empty(); bool is_public = !dialog_username.empty();
if (m->content->get_type() == MessageContentType::VideoNote && is_broadcast_channel(dialog_id) && is_public) { if (m->content->get_type() == MessageContentType::VideoNote && is_broadcast_channel(dialog_id) && is_public) {
return std::make_pair( return std::make_pair(
PSTRING() << "https://telesco.pe/" << dialog_username << '/' << m->message_id.get_server_message_id().get(), PSTRING() << "https://telesco.pe/" << dialog_username << '/' << message_id.get_server_message_id().get(), true);
true);
} }
if (is_public) { if (is_public) {
@ -17393,7 +17421,7 @@ Result<std::pair<string, bool>> MessagesManager::get_message_link(FullMessageId
} else { } else {
sb << "c/" << dialog_id.get_channel_id().get(); sb << "c/" << dialog_id.get_channel_id().get();
} }
sb << '/' << m->message_id.get_server_message_id().get(); sb << '/' << message_id.get_server_message_id().get();
char separator = '?'; char separator = '?';
if (for_comment) { if (for_comment) {
@ -22800,6 +22828,7 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
bool can_be_forwarded = for_event_log ? false : can_forward_message(dialog_id, m); bool can_be_forwarded = for_event_log ? false : can_forward_message(dialog_id, m);
bool can_get_statistics = for_event_log ? false : can_get_message_statistics(dialog_id, m); bool can_get_statistics = for_event_log ? false : can_get_message_statistics(dialog_id, m);
bool can_get_message_thread = for_event_log ? false : get_top_thread_full_message_id(dialog_id, m).is_ok(); bool can_get_message_thread = for_event_log ? false : get_top_thread_full_message_id(dialog_id, m).is_ok();
bool can_get_media_timestamp_links = for_event_log ? false : can_get_media_timestamp_link(dialog_id, m).is_ok();
auto via_bot_user_id = td_->contacts_manager_->get_user_id_object(m->via_bot_user_id, "via_bot_user_id"); auto via_bot_user_id = td_->contacts_manager_->get_user_id_object(m->via_bot_user_id, "via_bot_user_id");
auto media_album_id = for_event_log ? static_cast<int64>(0) : m->media_album_id; auto media_album_id = for_event_log ? static_cast<int64>(0) : m->media_album_id;
auto reply_to_message_id = for_event_log ? static_cast<int64>(0) : m->reply_to_message_id.get(); auto reply_to_message_id = for_event_log ? static_cast<int64>(0) : m->reply_to_message_id.get();
@ -22817,10 +22846,10 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
m->message_id.get(), get_message_sender_object_const(m->sender_user_id, m->sender_dialog_id, source.c_str()), m->message_id.get(), get_message_sender_object_const(m->sender_user_id, m->sender_dialog_id, source.c_str()),
dialog_id.get(), std::move(sending_state), std::move(scheduling_state), is_outgoing, is_pinned, can_be_edited, dialog_id.get(), std::move(sending_state), std::move(scheduling_state), is_outgoing, is_pinned, can_be_edited,
can_be_forwarded, can_delete_for_self, can_delete_for_all_users, can_get_statistics, can_get_message_thread, can_be_forwarded, can_delete_for_self, can_delete_for_all_users, can_get_statistics, can_get_message_thread,
m->is_channel_post, contains_unread_mention, date, edit_date, get_message_forward_info_object(m->forward_info), can_get_media_timestamp_links, m->is_channel_post, contains_unread_mention, date, edit_date,
get_message_interaction_info_object(dialog_id, m), reply_in_dialog_id.get(), reply_to_message_id, get_message_forward_info_object(m->forward_info), get_message_interaction_info_object(dialog_id, m),
top_thread_message_id, ttl, ttl_expires_in, via_bot_user_id, m->author_signature, media_album_id, reply_in_dialog_id.get(), reply_to_message_id, top_thread_message_id, ttl, ttl_expires_in, via_bot_user_id,
get_restriction_reason_description(m->restriction_reasons), m->author_signature, media_album_id, get_restriction_reason_description(m->restriction_reasons),
get_message_content_object(m->content.get(), td_, dialog_id, live_location_date, m->is_content_secret, get_message_content_object(m->content.get(), td_, dialog_id, live_location_date, m->is_content_secret,
skip_bot_commands), skip_bot_commands),
get_reply_markup_object(m->reply_markup)); get_reply_markup_object(m->reply_markup));

View File

@ -1776,6 +1776,8 @@ class MessagesManager final : public Actor {
Status can_pin_messages(DialogId dialog_id) const; Status can_pin_messages(DialogId dialog_id) const;
static Status can_get_media_timestamp_link(DialogId dialog_id, const Message *m);
void cancel_edit_message_media(DialogId dialog_id, Message *m, Slice error_message); void cancel_edit_message_media(DialogId dialog_id, Message *m, Slice error_message);
void on_message_media_edited(DialogId dialog_id, MessageId message_id, FileId file_id, FileId thumbnail_file_id, void on_message_media_edited(DialogId dialog_id, MessageId message_id, FileId file_id, FileId thumbnail_file_id,

View File

@ -1185,7 +1185,7 @@ tl_object_ptr<td_api::webPage> WebPagesManager::get_web_page_object(WebPageId we
FormattedText description; FormattedText description;
description.text = web_page->description; description.text = web_page->description;
description.entities = find_entities(web_page->description, true, true); description.entities = find_entities(web_page->description, true, false);
auto r_url = parse_url(web_page->display_url); auto r_url = parse_url(web_page->display_url);
if (r_url.is_ok()) { if (r_url.is_ok()) {