Add messageProperties.can_be_pinned.

This commit is contained in:
levlam 2024-07-09 13:11:05 +03:00
parent 83744e728a
commit 03dbbf0b04
3 changed files with 31 additions and 24 deletions

View File

@ -3836,6 +3836,7 @@ inputMessageForwarded from_chat_id:int53 message_id:int53 in_game_share:Bool cop
//-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
//@can_be_pinned True, if the message can be pinned or unpinned in the chat using pinChatMessage or unpinChatMessage
//@can_be_replied True, if the message can be replied in the same chat and forum topic using inputMessageReplyToMessage
//@can_be_replied_in_another_chat True, if the message can be replied in another chat or forum topic using inputMessageReplyToExternalMessage
//@can_be_reported True, if the message can be reported using reportSupergroupSpam or reportChat
@ -3853,7 +3854,7 @@ inputMessageForwarded from_chat_id:int53 message_id:int53 in_game_share:Bool cop
//@can_report_reactions True, if reactions on the message can be reported through reportMessageReactions
//@can_recognize_speech True, if speech can be recognized for the message through recognizeSpeech
//@can_set_fact_check True, if fact check for the message can be changed through setMessageFactCheck
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_edit_scheduling_state: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 can_recognize_speech:Bool can_set_fact_check: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_pinned: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_edit_scheduling_state: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 can_recognize_speech:Bool can_set_fact_check:Bool = MessageProperties;
//@class SearchMessagesFilter @description Represents a filter for message search results
@ -8996,7 +8997,7 @@ getBusinessConnection connection_id:string = BusinessConnection;
//@description Returns information about a button of type inlineKeyboardButtonTypeLoginUrl. The method needs to be called when the user presses the button
//@chat_id Chat identifier of the message with the button
//@message_id Message identifier of the message with the button
//@message_id Message identifier of the message with the button. The message must not be scheduled
//@button_id Button identifier
getLoginUrlInfo chat_id:int53 message_id:int53 button_id:int53 = LoginUrlInfo;
@ -9096,7 +9097,7 @@ answerWebAppQuery web_app_query_id:string result:InputInlineQueryResult = SentWe
//@description Sends a callback query to a bot and returns an answer. Returns an error with code 502 if the bot fails to answer the query before the query timeout expires
//@chat_id Identifier of the chat with the message
//@message_id Identifier of the message from which the query originated
//@message_id Identifier of the message from which the query originated. The message must not be scheduled
//@payload Query payload
getCallbackQueryAnswer chat_id:int53 message_id:int53 payload:CallbackQueryPayload = CallbackQueryAnswer;
@ -9429,7 +9430,7 @@ setChatLocation chat_id:int53 location:chatLocation = Ok;
//@description Changes the slow mode delay of a chat. Available only for supergroups; requires can_restrict_members right @chat_id Chat identifier @slow_mode_delay New slow mode delay for the chat, in seconds; must be one of 0, 10, 30, 60, 300, 900, 3600
setChatSlowModeDelay chat_id:int53 slow_mode_delay:int32 = Ok;
//@description Pins a message in a chat; requires can_pin_messages member right if the chat is a basic group or supergroup, or can_edit_messages administrator right if the chat is a channel
//@description Pins a message in a chat. A message can be pinned only if messageProperties.can_be_pinned
//@chat_id Identifier of the chat
//@message_id Identifier of the new pinned message
//@disable_notification Pass true to disable notification about the pinned message. Notifications are always disabled in channels and private chats

View File

@ -17347,6 +17347,7 @@ void MessagesManager::get_message_properties(DialogId dialog_id, MessageId messa
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_paid = get_invoice_message_id({dialog_id, m->message_id}).is_ok();
auto can_be_pinned = can_pin_message(dialog_id, m).is_ok();
auto can_be_replied =
message_id.is_valid() && !(message_id == MessageId(ServerMessageId(1)) && dialog_type == DialogType::Channel) &&
m->message_id.is_yet_unsent() && (!m->message_id.is_local() || dialog_type == DialogType::SecretChat) &&
@ -17367,11 +17368,11 @@ void MessagesManager::get_message_properties(DialogId dialog_id, MessageId messa
auto can_recognize_speech = can_recognize_message_speech(dialog_id, m);
auto can_set_fact_check = can_set_message_fact_check(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_edit_scheduling_state,
can_get_added_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,
can_recognize_speech, can_set_fact_check));
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_reported, can_be_saved, can_be_shared_in_story,
can_edit_scheduling_state, can_get_added_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, can_recognize_speech, can_set_fact_check));
}
bool MessagesManager::is_message_edited_recently(MessageFullId message_full_id, int32 seconds) {
@ -25261,6 +25262,23 @@ bool MessagesManager::can_edit_message(DialogId dialog_id, const Message *m, boo
}
}
Status MessagesManager::can_pin_message(DialogId dialog_id, const Message *m) const {
if (m == nullptr) {
return Status::Error(400, "Message not found");
}
TRY_STATUS(td_->dialog_manager_->can_pin_messages(dialog_id));
if (m->message_id.is_scheduled()) {
return Status::Error(400, "Scheduled message can't be pinned");
}
if (!m->message_id.is_server()) {
return Status::Error(400, "Message can't be pinned");
}
if (is_service_message_content(m->content->get_type())) {
return Status::Error(400, "Service messages can't be pinned");
}
return Status::OK();
}
bool MessagesManager::can_resend_message(const Message *m) const {
if (m->send_error_code != 429 && m->send_error_message != "Message is too old to be re-sent automatically" &&
m->send_error_message != "SCHEDULE_TOO_MUCH" && m->send_error_message != "SEND_AS_PEER_INVALID" &&
@ -31982,22 +32000,8 @@ void MessagesManager::pin_dialog_message(DialogId dialog_id, MessageId message_i
if (d == nullptr) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
TRY_STATUS_PROMISE(promise, td_->dialog_manager_->can_pin_messages(dialog_id));
const Message *m = get_message_force(d, message_id, "pin_dialog_message");
if (m == nullptr) {
return promise.set_error(Status::Error(400, "Message not found"));
}
if (message_id.is_scheduled()) {
return promise.set_error(Status::Error(400, "Scheduled message can't be pinned"));
}
if (!message_id.is_server()) {
return promise.set_error(Status::Error(400, "Message can't be pinned"));
}
if (is_service_message_content(m->content->get_type())) {
return promise.set_error(Status::Error(400, "A service message can't be pinned"));
}
TRY_STATUS_PROMISE(promise, can_pin_message(dialog_id, m));
if (only_for_self && dialog_id.get_type() != DialogType::User) {
return promise.set_error(Status::Error(400, "Messages can't be pinned only for self in the chat"));

View File

@ -1734,6 +1734,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;
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);
bool can_report_message_reactions(DialogId dialog_id, const Message *m) const;