From aa01368b380c030273f18936e4cd5d3d8b975617 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 3 Dec 2019 03:12:41 +0300 Subject: [PATCH] Add Message.scheduling_state. GitOrigin-RevId: fd950850b1258f49f8272e99a0b4975ab11a38d6 --- td/generate/scheme/td_api.tl | 12 +++++++++++- td/generate/scheme/td_api.tlo | Bin 164588 -> 164876 bytes td/telegram/MessagesManager.cpp | 21 +++++++++++++++------ td/telegram/MessagesManager.h | 4 ++++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 96253d6a..df631bad 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -542,6 +542,7 @@ messageSendingStateFailed error_code:int32 error_message:string can_retry:Bool r //@sender_user_id Identifier of the user who sent the message; 0 if unknown. Currently, it is unknown for channel posts and for channel posts automatically forwarded to discussion group //@chat_id Chat identifier //@sending_state Information about the sending state of the message; may be null +//@scheduling_state Information about the scheduling state of the message; may be null //@is_outgoing True, if the message is outgoing //@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 client //@can_be_forwarded True, if the message can be forwarded @@ -562,7 +563,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 //@content Content of the message //@reply_markup Reply markup for the message; may be null -message id:int53 sender_user_id:int32 chat_id:int53 sending_state:MessageSendingState is_outgoing:Bool can_be_edited:Bool can_be_forwarded:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool is_channel_post:Bool contains_unread_mention:Bool date:int32 edit_date:int32 forward_info:messageForwardInfo reply_to_message_id:int53 ttl:int32 ttl_expires_in:double via_bot_user_id:int32 author_signature:string views:int32 media_album_id:int64 restriction_reason:string content:MessageContent reply_markup:ReplyMarkup = Message; +message id:int53 sender_user_id:int32 chat_id:int53 sending_state:MessageSendingState scheduling_state:MessageSchedulingState is_outgoing:Bool can_be_edited:Bool can_be_forwarded:Bool can_be_deleted_only_for_self:Bool can_be_deleted_for_all_users:Bool is_channel_post:Bool contains_unread_mention:Bool date:int32 edit_date:int32 forward_info:messageForwardInfo reply_to_message_id:int53 ttl:int32 ttl_expires_in:double via_bot_user_id:int32 author_signature:string views:int32 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 messages total_count:int32 messages:vector = Messages; @@ -1480,6 +1481,15 @@ textEntityTypeMentionName user_id:int32 = TextEntityType; inputThumbnail thumbnail:InputFile width:int32 height:int32 = InputThumbnail; +//@class MessageSchedulingState @description Contains information about the time when a scheduled message will be sent + +//@description The message will be sent at the specified date @send_date Date the message will be sent +messageSchedulingStateSendAtDate send_date:int32 = MessageSchedulingState; + +//@description The message will be sent when the peer will be online. Applicable to private chats only and when the exact online status of the peer is known +messageSchedulingStateSendWhenOnline = MessageSchedulingState; + + //@class InputMessageContent @description The content of a message to send //@description A text message @text Formatted text to be sent; 1-GetOption("message_text_length_max") characters. Only Bold, Italic, Underline, Strikethrough, Code, Pre, PreCode, TextUrl and MentionName entities are allowed to be specified manually diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index ed823aa273c38cd832cff5021f5b87d99e2ed829..bc35afe92d4e80bdc4e40671973484833d6ef6c9 100644 GIT binary patch delta 872 zcmaFU%GJ}s#rtTsz7+!${M^XfF3KWmyxw*44ADEX@72%T7V}LlE>28O4NlHTO)1UE z%u5e0Ni0caV457rD!#cytV4u}fqC;kEinbKzUdF9Fluae@ZQ4(=1vNO2v1IkQkd)# zW&<%B#94yOVF^dbY)%Q!FbAvKe4#HRTomLQ_FRY~K_ybb{)UgJlU!WCtbQSk7IeW>U0DD)7V?!}4; z*1;<-cR=YQ`rM9gF5ki_f#xkFTFCKzfyOz5$6`cXC7M-)&%eP4si7u(|JM@- z&A36=#D75%QSdr@f{9_&XrwueL8N$Q1Li)XCB@zdx}YrgR3*Gd#Umc_V~F6S9~)_c Yq@t94oyJiduO@#bfF}9lvv}O_17WZ!?f?J) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 01f91c54..da685829 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -16771,6 +16771,13 @@ void MessagesManager::load_messages(DialogId dialog_id, MessageId from_message_i get_history(dialog_id, from_message_id, offset, limit, from_database, only_local, std::move(promise)); } +tl_object_ptr MessagesManager::get_message_scheduling_state_object(int32 send_date) { + if (send_date == SCHEDULE_WHEN_ONLINE_DATE) { + return td_api::make_object(); + } + return td_api::make_object(send_date); +} + tl_object_ptr MessagesManager::get_message_object(FullMessageId full_message_id) { return get_message_object(full_message_id.get_dialog_id(), get_message_force(full_message_id, "get_message_object")); } @@ -16803,6 +16810,7 @@ tl_object_ptr MessagesManager::get_message_object(DialogId dial can_delete = can_delete_channel_message(dialog_status, m, is_bot); } + bool is_scheduled = m->message_id.is_scheduled(); DialogId my_dialog_id = get_my_dialog_id(); bool can_delete_for_self = false; bool can_delete_for_all_users = can_delete && can_revoke_message(dialog_id, m); @@ -16825,7 +16833,7 @@ tl_object_ptr MessagesManager::get_message_object(DialogId dial if (for_event_log) { can_delete_for_self = false; can_delete_for_all_users = false; - } else if (m->message_id.is_scheduled()) { + } else if (is_scheduled) { can_delete_for_self = (dialog_id == my_dialog_id); can_delete_for_all_users = !can_delete_for_self; } @@ -16836,7 +16844,7 @@ tl_object_ptr MessagesManager::get_message_object(DialogId dial // 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 auto forward_info = m->forward_info.get(); - is_outgoing = m->message_id.is_scheduled() || forward_info == nullptr || + is_outgoing = is_scheduled || forward_info == nullptr || (!forward_info->from_dialog_id.is_valid() && !is_forward_info_sender_hidden(forward_info)); } @@ -16851,19 +16859,20 @@ tl_object_ptr MessagesManager::get_message_object(DialogId dial } else { ttl = 0; } + auto scheduling_state = is_scheduled ? get_message_scheduling_state_object(m->date) : nullptr; bool can_be_edited = for_event_log ? false : can_edit_message(dialog_id, m, false, is_bot); bool can_be_forwarded = for_event_log ? false : can_forward_message(dialog_id, m); auto media_album_id = for_event_log ? static_cast(0) : m->media_album_id; auto reply_to_message_id = for_event_log ? static_cast(0) : m->reply_to_message_id.get(); bool contains_unread_mention = for_event_log ? false : m->contains_unread_mention; auto live_location_date = m->is_failed_to_send ? 0 : m->date; - auto date = m->message_id.is_scheduled() ? 0 : m->date; + auto date = is_scheduled ? 0 : m->date; auto edit_date = m->hide_edit_date ? 0 : m->edit_date; return make_tl_object( m->message_id.get(), td_->contacts_manager_->get_user_id_object(m->sender_user_id, "sender_user_id"), - dialog_id.get(), std::move(sending_state), is_outgoing, can_be_edited, can_be_forwarded, can_delete_for_self, - can_delete_for_all_users, m->is_channel_post, contains_unread_mention, date, edit_date, - get_message_forward_info_object(m->forward_info), reply_to_message_id, ttl, ttl_expires_in, + dialog_id.get(), std::move(sending_state), std::move(scheduling_state), is_outgoing, can_be_edited, + can_be_forwarded, can_delete_for_self, can_delete_for_all_users, m->is_channel_post, contains_unread_mention, + date, edit_date, get_message_forward_info_object(m->forward_info), reply_to_message_id, ttl, ttl_expires_in, td_->contacts_manager_->get_user_id_object(m->via_bot_user_id, "via_bot_user_id"), m->author_signature, m->views, media_album_id, get_restriction_reason_description(m->restriction_reasons), get_message_content_object(m->content.get(), td_, live_location_date, m->is_content_secret), diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 21d028f4..fd152628 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1412,6 +1412,8 @@ class MessagesManager : public Actor { static constexpr int32 MAX_PRELOADED_DIALOGS = 1000; + static constexpr int32 SCHEDULE_WHEN_ONLINE_DATE = 2147483646; + static constexpr double DIALOG_ACTION_TIMEOUT = 5.5; static constexpr const char *DELETE_MESSAGE_USER_REQUEST_SOURCE = "user request"; @@ -1855,6 +1857,8 @@ class MessagesManager : public Actor { void hide_dialog_action_bar(Dialog *d); + static tl_object_ptr get_message_scheduling_state_object(int32 send_date); + tl_object_ptr get_message_object(DialogId dialog_id, const Message *m, bool for_event_log = false) const;