Add td_api::getMessageProperties.

This commit is contained in:
levlam 2024-07-08 14:08:45 +03:00
parent e659ae483c
commit 9006d75603
6 changed files with 108 additions and 65 deletions

View File

@ -1578,19 +1578,7 @@ factCheck text:formattedText country_code:string = FactCheck;
//@is_outgoing True, if the message is outgoing
//@is_pinned True, if the message is pinned
//@is_from_offline True, if the message was sent because of a scheduled action by the message sender, for example, as away, or greeting service message
//@can_be_edited True, if the message can be edited. For live location and poll messages this fields shows whether editMessageLiveLocation or stopPoll can be used with this message by the application
//@can_be_forwarded True, if the message can be forwarded
//@can_be_replied_in_another_chat True, if the message can be replied in another chat or topic
//@can_be_saved True, if content of the message can be saved locally or copied
//@can_be_deleted_only_for_self True, if the message can be deleted only for the current user while other users will continue to see it
//@can_be_deleted_for_all_users True, if the message can be deleted for all users
//@can_get_added_reactions True, if the list of added reactions is available through getMessageAddedReactions
//@can_get_statistics True, if the message statistics are available through getMessageStatistics
//@can_get_message_thread True, if information about the message thread is available through getMessageThread and getMessageThreadHistory
//@can_get_read_date True, if read date of the message can be received through getMessageReadDate
//@can_get_viewers True, if chat members already viewed the message can be received through getMessageViewers
//@can_get_media_timestamp_links True, if media timestamp links can be generated for media timestamp entities in the message text, caption or link preview description through getMessageLink
//@can_report_reactions True, if reactions on the message can be reported through reportMessageReactions
//@has_timestamped_media True, if media timestamp entities refers to a media in this message as opposed to a media in the replied message
//@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_topic_message True, if the message is a forum topic message
@ -1617,7 +1605,8 @@ factCheck text:formattedText country_code:string = FactCheck;
//@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
//@reply_markup Reply markup for the message; may be null if none
message id:int53 sender_id:MessageSender chat_id:int53 sending_state:MessageSendingState scheduling_state:MessageSchedulingState is_outgoing:Bool is_pinned:Bool is_from_offline:Bool can_be_edited:Bool can_be_forwarded:Bool can_be_replied_in_another_chat:Bool can_be_saved:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_get_added_reactions:Bool can_get_statistics:Bool can_get_message_thread:Bool can_get_read_date:Bool can_get_viewers:Bool can_get_media_timestamp_links:Bool can_report_reactions:Bool has_timestamped_media:Bool is_channel_post:Bool is_topic_message:Bool contains_unread_mention:Bool date:int32 edit_date:int32 forward_info:messageForwardInfo import_info:messageImportInfo interaction_info:messageInteractionInfo unread_reactions:vector<unreadReaction> fact_check:factCheck reply_to:MessageReplyTo message_thread_id:int53 saved_messages_topic_id:int53 self_destruct_type:MessageSelfDestructType self_destruct_in:double auto_delete_in:double via_bot_user_id:int53 sender_business_bot_user_id:int53 sender_boost_count:int32 author_signature:string media_album_id:int64 effect_id:int64 restriction_reason:string content:MessageContent reply_markup:ReplyMarkup = Message;
message id:int53 sender_id:MessageSender chat_id:int53 sending_state:MessageSendingState scheduling_state:MessageSchedulingState is_outgoing:Bool is_pinned:Bool is_from_offline:Bool can_be_saved:Bool has_timestamped_media:Bool is_channel_post:Bool is_topic_message:Bool contains_unread_mention:Bool date:int32 edit_date:int32 forward_info:messageForwardInfo import_info:messageImportInfo interaction_info:messageInteractionInfo unread_reactions:vector<unreadReaction> fact_check:factCheck reply_to:MessageReplyTo message_thread_id:int53 saved_messages_topic_id:int53 self_destruct_type:MessageSelfDestructType self_destruct_in:double auto_delete_in:double via_bot_user_id:int53 sender_business_bot_user_id:int53 sender_boost_count:int32 author_signature:string media_album_id:int64 effect_id:int64 restriction_reason:string content:MessageContent reply_markup:ReplyMarkup = Message;
//@description Contains a list of messages @total_count Approximate total number of messages found @messages List of messages; messages may be null
messages total_count:int32 messages:vector<message> = Messages;
@ -3838,6 +3827,23 @@ inputMessageStory story_sender_chat_id:int53 story_id:int32 = InputMessageConten
inputMessageForwarded from_chat_id:int53 message_id:int53 in_game_share:Bool copy_options:messageCopyOptions = InputMessageContent;
//@description Contains properties of a message and describes actions that can be done with the message right now
//@can_be_deleted_only_for_self True, if the message can be deleted only for the current user while other users will continue to see it
//@can_be_deleted_for_all_users True, if the message can be deleted for all users
//@can_be_edited True, if the message can be edited. For live location and poll messages this fields shows whether editMessageLiveLocation or stopPoll can be used with this message by the application
//@can_be_forwarded True, if the message can be forwarded
//@can_be_replied_in_another_chat True, if the message can be replied in another chat or topic
//@can_be_saved True, if content of the message can be saved locally or copied
//@can_get_added_reactions True, if the list of added reactions is available through getMessageAddedReactions
//@can_get_media_timestamp_links True, if media timestamp links can be generated for media timestamp entities in the message text, caption or link preview description through getMessageLink
//@can_get_message_thread True, if information about the message thread is available through getMessageThread and getMessageThreadHistory
//@can_get_read_date True, if read date of the message can be received through getMessageReadDate
//@can_get_statistics True, if the message statistics are available through getMessageStatistics
//@can_get_viewers True, if chat members already viewed the message can be received through getMessageViewers
//@can_report_reactions True, if reactions on the message can be reported through reportMessageReactions
messageProperties can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool can_be_edited:Bool can_be_forwarded:Bool can_be_replied_in_another_chat:Bool can_be_saved:Bool can_get_added_reactions:Bool can_get_media_timestamp_links:Bool can_get_message_thread:Bool can_get_read_date:Bool can_get_statistics:Bool can_get_viewers:Bool can_report_reactions:Bool = MessageProperties;
//@class SearchMessagesFilter @description Represents a filter for message search results
//@description Returns all found messages, no filter is applied
@ -8064,6 +8070,9 @@ getCallbackQueryMessage chat_id:int53 message_id:int53 callback_query_id:int64 =
//@description Returns information about messages. If a message is not found, returns null on the corresponding position of the result @chat_id Identifier of the chat the messages belong to @message_ids Identifiers of the messages to get
getMessages chat_id:int53 message_ids:vector<int53> = Messages;
//@description Returns properties of a message; this is an offline request @chat_id Chat identifier @message_id Identifier of the message
getMessageProperties chat_id:int53 message_id:int53 = MessageProperties;
//@description Returns information about a message thread. Can be used only if message.can_get_message_thread == true @chat_id Chat identifier @message_id Identifier of the message
getMessageThread chat_id:int53 message_id:int53 = MessageThreadInfo;

View File

@ -17294,6 +17294,62 @@ void MessagesManager::get_messages_from_server(vector<MessageFullId> &&message_i
lock.set_value(Unit());
}
void MessagesManager::get_message_properties(DialogId dialog_id, MessageId message_id,
Promise<td_api::object_ptr<td_api::messageProperties>> &&promise) {
TRY_RESULT_PROMISE(promise, d, check_dialog_access(dialog_id, true, AccessRights::Read, "get_message_properties"));
const Message *m = get_message_force(d, message_id, "get_message_properties");
if (m == nullptr) {
if (message_id.is_valid_sponsored()) {
return promise.set_value(td_api::make_object<td_api::messageProperties>(
false, false, false, false, false, false, false, false, false, false, false, false, false));
}
return promise.set_error(Status::Error(400, "Message not found"));
}
bool can_delete = can_delete_message(dialog_id, m);
bool is_scheduled = m->message_id.is_scheduled();
bool is_from_saved_messages = (dialog_id == td_->dialog_manager_->get_my_dialog_id());
bool can_delete_for_self = false;
bool can_delete_for_all_users = can_delete && can_revoke_message(dialog_id, m);
if (can_delete) {
switch (dialog_id.get_type()) {
case DialogType::User:
case DialogType::Chat:
// TODO allow to delete yet unsent message just for self
can_delete_for_self = !m->message_id.is_yet_unsent() || is_from_saved_messages;
break;
case DialogType::Channel:
case DialogType::SecretChat:
can_delete_for_self = !can_delete_for_all_users;
break;
case DialogType::None:
default:
UNREACHABLE();
}
}
if (is_scheduled) {
can_delete_for_self = is_from_saved_messages;
can_delete_for_all_users = !can_delete_for_self;
}
auto is_bot = td_->auth_manager_->is_bot();
auto can_be_saved = can_save_message(dialog_id, m);
auto can_be_edited = can_edit_message(dialog_id, m, false, is_bot);
auto can_be_forwarded = can_be_saved && can_forward_message(dialog_id, m);
auto can_be_replied_in_another_chat = can_be_forwarded && m->message_id.is_server();
auto can_get_added_reactions = m->reactions != nullptr && m->reactions->can_get_added_reactions_;
auto can_get_statistics = can_get_message_statistics(dialog_id, m);
auto can_get_message_thread = get_top_thread_message_full_id(dialog_id, m, false).is_ok();
auto can_get_read_date = can_get_message_read_date(dialog_id, m).is_ok();
auto can_get_viewers = can_get_message_viewers(dialog_id, m).is_ok();
auto can_get_media_timestamp_links = can_get_media_timestamp_link(dialog_id, m).is_ok();
auto can_report_reactions = can_report_message_reactions(dialog_id, m);
promise.set_value(td_api::make_object<td_api::messageProperties>(
can_delete_for_self, can_delete_for_all_users, can_be_edited, can_be_forwarded, can_be_replied_in_another_chat,
can_be_saved, can_get_added_reactions, can_get_media_timestamp_links, can_get_message_thread, can_get_read_date,
can_get_statistics, can_get_viewers, can_report_reactions));
}
bool MessagesManager::is_message_edited_recently(MessageFullId message_full_id, int32 seconds) {
if (seconds < 0) {
return false;
@ -22690,11 +22746,11 @@ td_api::object_ptr<td_api::message> MessagesManager::get_dialog_event_log_messag
get_message_own_max_media_timestamp(m), m->invert_media, m->disable_web_page_preview);
return td_api::make_object<td_api::message>(
m->message_id.get(), std::move(sender), get_chat_id_object(dialog_id, "get_dialog_event_log_message_object"),
nullptr, nullptr, m->is_outgoing, m->is_pinned, m->is_from_offline, false, false, false, can_be_saved, false,
false, false, false, false, false, false, false, false, true, m->is_channel_post, m->is_topic_message, false,
m->date, edit_date, std::move(forward_info), std::move(import_info), std::move(interaction_info), Auto(), nullptr,
nullptr, 0, 0, nullptr, 0.0, 0.0, via_bot_user_id, 0, m->sender_boost_count, m->author_signature, 0, 0,
get_restriction_reason_description(m->restriction_reasons), std::move(content), std::move(reply_markup));
nullptr, nullptr, m->is_outgoing, m->is_pinned, m->is_from_offline, can_be_saved, true, m->is_channel_post,
m->is_topic_message, false, m->date, edit_date, std::move(forward_info), std::move(import_info),
std::move(interaction_info), Auto(), nullptr, nullptr, 0, 0, nullptr, 0.0, 0.0, via_bot_user_id, 0,
m->sender_boost_count, m->author_signature, 0, 0, get_restriction_reason_description(m->restriction_reasons),
std::move(content), std::move(reply_markup));
}
td_api::object_ptr<td_api::businessMessage> MessagesManager::get_business_message_object(
@ -22758,10 +22814,9 @@ td_api::object_ptr<td_api::message> MessagesManager::get_business_message_messag
return td_api::make_object<td_api::message>(
m->message_id.get(), std::move(sender), get_chat_id_object(dialog_id, "get_business_message_message_object"),
nullptr, nullptr, m->is_outgoing, m->is_from_offline, false, false, false, false, can_be_saved, false, false,
false, false, false, false, false, false, false, false, false, false, false, m->date, m->edit_date,
std::move(forward_info), std::move(import_info), nullptr, Auto(), nullptr, std::move(reply_to), 0, 0,
std::move(self_destruct_type), 0.0, 0.0, via_bot_user_id, via_business_bot_user_id, 0, string(),
nullptr, nullptr, m->is_outgoing, false, m->is_from_offline, can_be_saved, false, false, false, false, m->date,
m->edit_date, std::move(forward_info), std::move(import_info), nullptr, Auto(), nullptr, std::move(reply_to), 0,
0, std::move(self_destruct_type), 0.0, 0.0, via_bot_user_id, via_business_bot_user_id, 0, string(),
m->media_album_id, m->effect_id.get(), get_restriction_reason_description(m->restriction_reasons),
std::move(content), std::move(reply_markup));
}
@ -22783,34 +22838,10 @@ td_api::object_ptr<td_api::message> MessagesManager::get_message_object(DialogId
if (sending_state == nullptr || !is_bot) {
m->is_update_sent = true;
}
bool can_delete = can_delete_message(dialog_id, m);
bool is_scheduled = m->message_id.is_scheduled();
DialogId my_dialog_id = td_->dialog_manager_->get_my_dialog_id();
bool can_delete_for_self = false;
bool can_delete_for_all_users = can_delete && can_revoke_message(dialog_id, m);
if (can_delete) {
switch (dialog_id.get_type()) {
case DialogType::User:
case DialogType::Chat:
// TODO allow to delete yet unsent message just for self
can_delete_for_self = !m->message_id.is_yet_unsent() || dialog_id == my_dialog_id;
break;
case DialogType::Channel:
case DialogType::SecretChat:
can_delete_for_self = !can_delete_for_all_users;
break;
case DialogType::None:
default:
UNREACHABLE();
}
}
if (is_scheduled) {
can_delete_for_self = (dialog_id == my_dialog_id);
can_delete_for_all_users = !can_delete_for_self;
}
bool is_from_saved_messages = (dialog_id == td_->dialog_manager_->get_my_dialog_id());
bool is_outgoing = m->is_outgoing;
if (dialog_id == my_dialog_id) {
if (is_from_saved_messages) {
// in Saved Messages all non-forwarded messages must be outgoing
// a forwarded message is outgoing, only if it doesn't have from_dialog_id and its sender isn't hidden
// i.e. a message is incoming only if it's a forwarded message with known from_dialog_id or with a hidden sender
@ -22827,22 +22858,12 @@ td_api::object_ptr<td_api::message> MessagesManager::get_message_object(DialogId
auto scheduling_state = is_scheduled ? get_message_scheduling_state_object(m->date) : nullptr;
auto forward_info = m->forward_info == nullptr
? nullptr
: m->forward_info->get_message_forward_info_object(td_, dialog_id == my_dialog_id);
: m->forward_info->get_message_forward_info_object(td_, is_from_saved_messages);
auto import_info = m->forward_info == nullptr ? nullptr : m->forward_info->get_message_import_info_object();
auto interaction_info = is_bot ? nullptr : get_message_interaction_info_object(dialog_id, m);
auto unread_reactions = get_unread_reactions_object(dialog_id, m);
auto fact_check = get_message_fact_check_object(m);
auto can_be_saved = can_save_message(dialog_id, m);
auto can_be_edited = can_edit_message(dialog_id, m, false, is_bot);
auto can_be_forwarded = can_be_saved && can_forward_message(dialog_id, m);
auto can_be_replied_in_another_chat = can_be_forwarded && m->message_id.is_server();
auto can_get_added_reactions = m->reactions != nullptr && m->reactions->can_get_added_reactions_;
auto can_get_statistics = can_get_message_statistics(dialog_id, m);
auto can_get_message_thread = get_top_thread_message_full_id(dialog_id, m, false).is_ok();
auto can_get_read_date = can_get_message_read_date(dialog_id, m).is_ok();
auto can_get_viewers = can_get_message_viewers(dialog_id, m).is_ok();
auto can_get_media_timestamp_links = can_get_media_timestamp_link(dialog_id, m).is_ok();
auto can_report_reactions = can_report_message_reactions(dialog_id, m);
auto via_bot_user_id =
td_->user_manager_->get_user_id_object(m->via_bot_user_id, "get_message_object via_bot_user_id");
auto via_business_bot_user_id = td_->user_manager_->get_user_id_object(m->via_business_bot_user_id,
@ -22873,12 +22894,9 @@ td_api::object_ptr<td_api::message> MessagesManager::get_message_object(DialogId
return td_api::make_object<td_api::message>(
m->message_id.get(), std::move(sender), get_chat_id_object(dialog_id, "get_message_object"),
std::move(sending_state), std::move(scheduling_state), is_outgoing, m->is_pinned, m->is_from_offline,
can_be_edited, can_be_forwarded, can_be_replied_in_another_chat, can_be_saved, can_delete_for_self,
can_delete_for_all_users, can_get_added_reactions, can_get_statistics, can_get_message_thread, can_get_read_date,
can_get_viewers, can_get_media_timestamp_links, can_report_reactions, has_timestamped_media, m->is_channel_post,
m->is_topic_message, m->contains_unread_mention, date, edit_date, std::move(forward_info), std::move(import_info),
std::move(interaction_info), std::move(unread_reactions), std::move(fact_check), std::move(reply_to),
top_thread_message_id,
can_be_saved, has_timestamped_media, m->is_channel_post, m->is_topic_message, m->contains_unread_mention, date,
edit_date, std::move(forward_info), std::move(import_info), std::move(interaction_info),
std::move(unread_reactions), std::move(fact_check), std::move(reply_to), top_thread_message_id,
td_->saved_messages_manager_->get_saved_messages_topic_id_object(m->saved_messages_topic_id),
std::move(self_destruct_type), ttl_expires_in, auto_delete_in, via_bot_user_id, via_business_bot_user_id,
m->sender_boost_count, m->author_signature, m->media_album_id, m->effect_id.get(),

View File

@ -583,6 +583,9 @@ class MessagesManager final : public Actor {
void get_messages_from_server(vector<MessageFullId> &&message_ids, Promise<Unit> &&promise, const char *source,
tl_object_ptr<telegram_api::InputMessage> input_message = nullptr);
void get_message_properties(DialogId dialog_id, MessageId message_id,
Promise<td_api::object_ptr<td_api::messageProperties>> &&promise);
void get_message_thread(DialogId dialog_id, MessageId message_id, Promise<MessageThreadInfo> &&promise);
td_api::object_ptr<td_api::messageThreadInfo> get_message_thread_info_object(const MessageThreadInfo &info);

View File

@ -4650,6 +4650,12 @@ void Td::on_request(uint64 id, const td_api::getMessages &request) {
CREATE_REQUEST(GetMessagesRequest, request.chat_id_, request.message_ids_);
}
void Td::on_request(uint64 id, const td_api::getMessageProperties &request) {
CREATE_REQUEST_PROMISE();
messages_manager_->get_message_properties(DialogId(request.chat_id_), MessageId(request.message_id_),
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getChatSponsoredMessages &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();

View File

@ -647,6 +647,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getMessages &request);
void on_request(uint64 id, const td_api::getMessageProperties &request);
void on_request(uint64 id, const td_api::getChatSponsoredMessages &request);
void on_request(uint64 id, const td_api::clickChatSponsoredMessage &request);

View File

@ -3868,6 +3868,11 @@ class CliClient final : public Actor {
string message_ids;
get_args(args, chat_id, message_ids);
send_request(td_api::make_object<td_api::getMessages>(chat_id, as_message_ids(message_ids)));
} else if (op == "gmp") {
ChatId chat_id;
MessageId message_id;
get_args(args, chat_id, message_ids);
send_request(td_api::make_object<td_api::getMessageProperties>(chat_id, message_id));
} else if (op == "gcspm") {
ChatId chat_id;
get_args(args, chat_id);