Add messageProperties.can_get_embedding_code.

This commit is contained in:
levlam 2024-07-08 22:27:13 +03:00
parent 1c921dd2b1
commit abb004d0de
3 changed files with 33 additions and 26 deletions

View File

@ -3842,6 +3842,7 @@ inputMessageForwarded from_chat_id:int53 message_id:int53 in_game_share:Bool cop
//@can_be_saved True, if content of the message can be saved locally or copied using inputMessageForwarded or forwardMessages with copy options
//@can_be_shared_in_story True, if the message can be shared in a story using inputStoryAreaTypeMessage
//@can_get_added_reactions True, if the list of added reactions is available using getMessageAddedReactions
//@can_get_embedding_code True, if code for message embedding can be received using getMessageEmbeddingCode
//@can_get_link True, if a link can be generated for the message using getMessageLink
//@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 using getMessageLink
//@can_get_message_thread True, if information about the message thread is available through getMessageThread and getMessageThreadHistory
@ -3849,7 +3850,7 @@ inputMessageForwarded from_chat_id:int53 message_id:int53 in_game_share:Bool cop
//@can_get_statistics True, if the message statistics are available through getMessageStatistics and message forwards can be received using getMessagePublicForwards
//@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_paid:Bool can_be_replied:Bool can_be_replied_in_another_chat:Bool can_be_reported:Bool can_be_saved:Bool can_be_shared_in_story:Bool can_get_added_reactions:Bool can_get_link: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;
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_paid:Bool can_be_replied:Bool can_be_replied_in_another_chat:Bool can_be_reported:Bool can_be_saved:Bool can_be_shared_in_story:Bool can_get_added_reactions:Bool can_get_embedding_code:Bool can_get_link: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
@ -8434,7 +8435,7 @@ removeNotificationGroup notification_group_id:int32 max_notification_id:int32 =
//@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
//@description Returns an HTML code for embedding the message. Available only if messageProperties.can_get_embedding_code
//@chat_id Identifier of the chat to which the message belongs
//@message_id Identifier of the message
//@for_album Pass true to return an HTML code for embedding of the whole media album

View File

@ -17312,7 +17312,7 @@ void MessagesManager::get_message_properties(DialogId dialog_id, MessageId messa
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, false, false,
false, false, false));
false, false, false, false));
}
return promise.set_error(Status::Error(400, "Message not found"));
}
@ -17363,12 +17363,13 @@ void MessagesManager::get_message_properties(DialogId dialog_id, MessageId messa
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_get_link = can_get_media_timestamp_links && dialog_type == DialogType::Channel;
auto can_get_embedding_code = can_get_message_embedding_code(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_paid, can_be_replied,
can_be_replied_in_another_chat, can_be_reported, can_be_saved, can_be_shared_in_story, can_get_added_reactions,
can_get_link, can_get_media_timestamp_links, can_get_message_thread, can_get_read_date, can_get_statistics,
can_get_viewers, can_report_reactions));
can_get_embedding_code, can_get_link, 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) {
@ -17601,6 +17602,27 @@ Result<std::pair<string, bool>> MessagesManager::get_message_link(MessageFullId
return std::make_pair(sb.as_cslice().str(), is_public);
}
Status MessagesManager::can_get_message_embedding_code(DialogId dialog_id, const Message *m) const {
if (dialog_id.get_type() != DialogType::Channel ||
td_->chat_manager_->get_channel_first_username(dialog_id.get_channel_id()).empty()) {
return Status::Error(
400, "Message embedding code is available only for messages in public supergroups and channel chats");
}
if (m == nullptr) {
return Status::Error(400, "Message not found");
}
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();
}
string MessagesManager::get_message_embedding_code(MessageFullId message_full_id, bool for_group,
Promise<Unit> &&promise) {
auto dialog_id = message_full_id.get_dialog_id();
@ -17610,28 +17632,10 @@ string MessagesManager::get_message_embedding_code(MessageFullId message_full_id
return {};
}
auto d = r_d.move_as_ok();
if (dialog_id.get_type() != DialogType::Channel ||
td_->chat_manager_->get_channel_first_username(dialog_id.get_channel_id()).empty()) {
promise.set_error(Status::Error(
400, "Message embedding code is available only for messages in public supergroups and channel chats"));
return {};
}
auto *m = get_message_force(d, message_full_id.get_message_id(), "get_message_embedding_code");
if (m == nullptr) {
promise.set_error(Status::Error(400, "Message not found"));
return {};
}
if (m->message_id.is_yet_unsent()) {
promise.set_error(Status::Error(400, "Message is not sent yet"));
return {};
}
if (m->message_id.is_scheduled()) {
promise.set_error(Status::Error(400, "Message is scheduled"));
return {};
}
if (!m->message_id.is_server()) {
promise.set_error(Status::Error(400, "Message is local"));
auto status = can_get_message_embedding_code(dialog_id, m);
if (status.is_error()) {
promise.set_error(std::move(status));
return {};
}

View File

@ -1923,6 +1923,8 @@ class MessagesManager final : public Actor {
bool can_get_message_statistics(DialogId dialog_id, const Message *m) const;
Status can_get_message_embedding_code(DialogId dialog_id, const Message *m) const;
struct CanDeleteDialog {
bool for_self_;
bool for_all_users_;