Skip to content

Commit

Permalink
Add messageProperties.can_edit_media.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Oct 29, 2024
1 parent 647d215 commit 47dbad0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
12 changes: 6 additions & 6 deletions td/generate/scheme/td_api.tl
Original file line number Diff line number Diff line change
Expand Up @@ -4068,7 +4068,7 @@ inputMessageForwarded from_chat_id:int53 message_id:int53 in_game_share:Bool cop
//@can_be_copied_to_secret_chat True, if content of the message can be copied to a secret chat using inputMessageForwarded or forwardMessages with copy options
//@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 using the method deleteMessages with revoke == false
//@can_be_deleted_for_all_users True, if the message can be deleted for all users using the method deleteMessages with revoke == true
//@can_be_edited True, if the message can be edited using the methods editMessageText, editMessageMedia, editMessageCaption, or editMessageReplyMarkup.
//@can_be_edited True, if the message can be edited using the methods editMessageText, editMessageCaption, or editMessageReplyMarkup.
//-For live location and poll messages this fields shows whether editMessageLiveLocation or stopPoll can be used with this message
//@can_be_forwarded True, if the message can be forwarded using inputMessageForwarded or forwardMessages
//@can_be_paid True, if the message can be paid using inputInvoiceMessage
Expand All @@ -4077,6 +4077,7 @@ inputMessageForwarded from_chat_id:int53 message_id:int53 in_game_share:Bool cop
//@can_be_replied_in_another_chat True, if the message can be replied in another chat or forum topic using inputMessageReplyToExternalMessage
//@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_edit_media True, if the message can be edited using the method editMessageMedia
//@can_edit_scheduling_state True, if scheduling state of the message can be edited
//@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
Expand All @@ -4091,7 +4092,7 @@ inputMessageForwarded from_chat_id:int53 message_id:int53 in_game_share:Bool cop
//@can_report_supergroup_spam True, if the message can be reported using reportSupergroupSpam
//@can_set_fact_check True, if fact check for the message can be changed through setMessageFactCheck
//@need_show_statistics True, if message statistics must be available from context menu of the message
messageProperties can_be_copied_to_secret_chat:Bool 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_pinned:Bool can_be_replied:Bool can_be_replied_in_another_chat:Bool can_be_saved:Bool can_be_shared_in_story:Bool can_edit_scheduling_state: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_recognize_speech:Bool can_report_chat:Bool can_report_reactions:Bool can_report_supergroup_spam:Bool can_set_fact_check:Bool need_show_statistics:Bool = MessageProperties;
messageProperties can_be_copied_to_secret_chat:Bool 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_pinned:Bool can_be_replied:Bool can_be_replied_in_another_chat:Bool can_be_saved:Bool can_be_shared_in_story:Bool can_edit_media:Bool can_edit_scheduling_state: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_recognize_speech:Bool can_report_chat:Bool can_report_reactions:Bool can_report_supergroup_spam:Bool can_set_fact_check:Bool need_show_statistics:Bool = MessageProperties;


//@class SearchMessagesFilter @description Represents a filter for message search results
Expand Down Expand Up @@ -8964,11 +8965,10 @@ editMessageText chat_id:int53 message_id:int53 reply_markup:ReplyMarkup input_me
//@proximity_alert_radius The new maximum distance for proximity alerts, in meters (0-100000). Pass 0 if the notification is disabled
editMessageLiveLocation chat_id:int53 message_id:int53 reply_markup:ReplyMarkup location:location live_period:int32 heading:int32 proximity_alert_radius:int32 = Message;

//@description Edits the media content of a message with a text, an animation, an audio, a document, a photo or a video, including message caption. If only the caption needs to be edited, use editMessageCaption instead.
//-The media can't be edited if the message was set to self-destruct or to a self-destructing media. The type of message content in an album can't be changed with exception of replacing a photo with a video or vice versa.
//-Returns the edited message after the edit is completed on the server side
//@description Edits the media content of a message, including message caption. If only the caption needs to be edited, use editMessageCaption instead.
//-The type of message content in an album can't be changed with exception of replacing a photo with a video or vice versa. Returns the edited message after the edit is completed on the server side
//@chat_id The chat the message belongs to
//@message_id Identifier of the message. Use messageProperties.can_be_edited to check whether the message can be edited
//@message_id Identifier of the message. Use messageProperties.can_edit_media to check whether the message can be edited
//@reply_markup The new message reply markup; pass null if none; for bots only
//@input_message_content New content of the message. Must be one of the following types: inputMessageAnimation, inputMessageAudio, inputMessageDocument, inputMessagePhoto or inputMessageVideo
editMessageMedia chat_id:int53 message_id:int53 reply_markup:ReplyMarkup input_message_content:InputMessageContent = Message;
Expand Down
44 changes: 29 additions & 15 deletions td/telegram/MessagesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17524,6 +17524,7 @@ void MessagesManager::get_message_properties(DialogId dialog_id, MessageId messa
can_send_message(dialog_id).is_ok();
auto can_be_replied_in_another_chat = can_be_forwarded && m->message_id.is_server();
auto can_be_shared_in_story = can_share_message_in_story(dialog_id, m);
auto can_edit_media = can_edit_message_media(dialog_id, m, false);
auto can_edit_scheduling_state = m->message_id.is_valid_scheduled() && m->message_id.is_scheduled_server();
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();
Expand All @@ -17546,7 +17547,7 @@ void MessagesManager::get_message_properties(DialogId dialog_id, MessageId messa
promise.set_value(td_api::make_object<td_api::messageProperties>(
can_be_copied_to_secret_chat, can_delete_for_self, can_delete_for_all_users, can_be_edited, can_be_forwarded,
can_be_paid, can_be_pinned, can_be_replied, can_be_replied_in_another_chat, can_be_saved, can_be_shared_in_story,
can_edit_scheduling_state, can_get_embedding_code, can_get_link, can_get_media_timestamp_links,
can_edit_media, can_edit_scheduling_state, 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_recognize_speech,
can_report_chat, can_report_reactions, can_report_supergroup_spam, can_set_fact_check, need_show_statistics));
}
Expand Down Expand Up @@ -25680,6 +25681,30 @@ bool MessagesManager::can_edit_message(DialogId dialog_id, const Message *m, boo
}
}

bool MessagesManager::can_edit_message_media(DialogId dialog_id, const Message *m, bool is_editing) const {
if (!can_edit_message(dialog_id, m, is_editing)) {
return false;
}
if (m->video_processing_pending) {
return false;
}
switch (m->content->get_type()) {
case MessageContentType::Text:
case MessageContentType::Animation:
case MessageContentType::Audio:
case MessageContentType::Document:
case MessageContentType::Photo:
case MessageContentType::Video:
break;
default:
return false;
}
if (!m->ttl.is_empty()) {
return false;
}
return true;
}

Status MessagesManager::can_pin_message(DialogId dialog_id, const Message *m) const {
if (m == nullptr) {
return Status::Error(400, "Message not found");
Expand Down Expand Up @@ -26021,29 +26046,18 @@ void MessagesManager::edit_message_media(MessageFullId message_full_id,
if (m == nullptr) {
return promise.set_error(Status::Error(400, "Message not found"));
}
if (!can_edit_message(dialog_id, m, true)) {
return promise.set_error(Status::Error(400, "Message can't be edited"));
if (!can_edit_message_media(dialog_id, m, true)) {
return promise.set_error(Status::Error(400, "Message media can't be edited"));
}
CHECK(m->message_id.is_any_server());

MessageContentType old_message_content_type = m->content->get_type();
if (old_message_content_type != MessageContentType::Text &&
old_message_content_type != MessageContentType::Animation &&
old_message_content_type != MessageContentType::Audio &&
old_message_content_type != MessageContentType::Document &&
old_message_content_type != MessageContentType::Photo && old_message_content_type != MessageContentType::Video) {
return promise.set_error(Status::Error(400, "The message can't be edited with a media"));
}
if (!m->ttl.is_empty()) {
return promise.set_error(Status::Error(400, "Can't edit media in self-destructing message"));
}

TRY_RESULT_PROMISE(promise, content, process_input_message_content(dialog_id, std::move(input_message_content)));
if (!content.ttl.is_empty()) {
return promise.set_error(Status::Error(400, "Can't enable self-destruction for media"));
}

if (m->media_album_id != 0) {
auto old_message_content_type = m->content->get_type();
auto new_content_type = content.content->get_type();
if (old_message_content_type != new_content_type) {
if (!is_allowed_media_group_content(new_content_type)) {
Expand Down
2 changes: 2 additions & 0 deletions td/telegram/MessagesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,8 @@ class MessagesManager final : public Actor {

bool can_edit_message(DialogId dialog_id, const Message *m, bool is_editing, bool only_reply_markup = false) const;

bool can_edit_message_media(DialogId dialog_id, const Message *m, bool is_editing) const;

Status can_pin_message(DialogId dialog_id, const Message *m) const TD_WARN_UNUSED_RESULT;

static Status can_get_media_timestamp_link(DialogId dialog_id, const Message *m);
Expand Down

0 comments on commit 47dbad0

Please sign in to comment.