diff --git a/td/telegram/CallbackQueriesManager.cpp b/td/telegram/CallbackQueriesManager.cpp index 3e5eb4665..d02e7b48a 100644 --- a/td/telegram/CallbackQueriesManager.cpp +++ b/td/telegram/CallbackQueriesManager.cpp @@ -241,6 +241,10 @@ int64 CallbackQueriesManager::send_callback_query(FullMessageId full_message_id, promise.set_error(Status::Error(5, "Message not found")); return 0; } + if (full_message_id.get_message_id().is_valid_scheduled()) { + promise.set_error(Status::Error(5, "Can't send callback queries from scheduled messages")); + return 0; + } if (!full_message_id.get_message_id().is_server()) { promise.set_error(Status::Error(5, "Bad message identifier")); return 0; diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 5fbe3f3e0..8341367b6 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -5274,6 +5274,10 @@ void ContactsManager::report_channel_spam(ChannelId channel_id, UserId user_id, vector server_message_ids; for (auto &message_id : message_ids) { + if (message_id.is_valid_scheduled()) { + return promise.set_error(Status::Error(6, "Can't report scheduled messages")); + } + if (!message_id.is_valid()) { return promise.set_error(Status::Error(6, "Message not found")); } diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 2b33c9d07..1d6ed3614 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -3360,6 +3360,9 @@ bool merge_message_content_file_id(Td *td, MessageContent *message_content, File } void register_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id) { + if (full_message_id.get_message_id().is_scheduled()) { + return; + } switch (content->get_type()) { case MessageContentType::Poll: return td->poll_manager_->register_poll(static_cast(content)->poll_id, full_message_id); @@ -3369,6 +3372,9 @@ void register_message_content(Td *td, const MessageContent *content, FullMessage } void unregister_message_content(Td *td, const MessageContent *content, FullMessageId full_message_id) { + if (full_message_id.get_message_id().is_scheduled()) { + return; + } switch (content->get_type()) { case MessageContentType::Poll: return td->poll_manager_->unregister_poll(static_cast(content)->poll_id, full_message_id); diff --git a/td/telegram/MessageId.cpp b/td/telegram/MessageId.cpp index 00bf9dac7..432634d80 100644 --- a/td/telegram/MessageId.cpp +++ b/td/telegram/MessageId.cpp @@ -64,10 +64,12 @@ MessageType MessageId::get_type() const { } ServerMessageId MessageId::get_server_message_id_force() const { + CHECK(!is_scheduled()); return ServerMessageId(narrow_cast(id >> SERVER_ID_SHIFT)); } MessageId MessageId::get_next_message_id(MessageType type) const { + CHECK(!is_scheduled()); switch (type) { case MessageType::Server: return get_next_server_message_id(); diff --git a/td/telegram/MessageId.h b/td/telegram/MessageId.h index f0bc88eb4..12f8c746c 100644 --- a/td/telegram/MessageId.h +++ b/td/telegram/MessageId.h @@ -43,6 +43,7 @@ class MessageId { ServerMessageId get_server_message_id_force() const; int32 get_scheduled_server_message_id_force() const { + CHECK(is_scheduled()); return static_cast((id >> 3) & ((1 << 18) - 1)); } @@ -108,11 +109,13 @@ class MessageId { // returns greatest server message id not bigger than this message id MessageId get_prev_server_message_id() const { + CHECK(!is_scheduled()); return MessageId(id & ~FULL_TYPE_MASK); } // returns smallest server message id not less than this message id MessageId get_next_server_message_id() const { + CHECK(!is_scheduled()); return MessageId((id + FULL_TYPE_MASK) & ~FULL_TYPE_MASK); } diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 77cc258f5..ed0c62b4b 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -25663,6 +25663,10 @@ bool MessagesManager::update_message_content(DialogId dialog_id, Message *old_me unique_ptr new_content, bool need_send_update_message_content, bool need_merge_files, bool is_message_in_dialog) { + if (old_message->message_id.is_scheduled()) { + is_message_in_dialog = false; + } + bool is_content_changed = false; bool need_update = false; unique_ptr &old_content = old_message->content; @@ -28336,6 +28340,9 @@ void MessagesManager::set_poll_answer(FullMessageId full_message_id, vectorcontent->get_type() != MessageContentType::Poll) { return promise.set_error(Status::Error(5, "Message is not a poll")); } + if (full_message_id.get_message_id().is_scheduled()) { + return promise.set_error(Status::Error(5, "Can't answer polls from scheduled messages")); + } if (!full_message_id.get_message_id().is_server()) { return promise.set_error(Status::Error(5, "Poll can't be answered")); } @@ -28361,6 +28368,9 @@ void MessagesManager::stop_poll(FullMessageId full_message_id, td_api::object_pt if (!can_edit_message(full_message_id.get_dialog_id(), m, true)) { return promise.set_error(Status::Error(5, "Poll can't be stopped")); } + if (full_message_id.get_message_id().is_scheduled()) { + return promise.set_error(Status::Error(5, "Can't stop polls from scheduled messages")); + } if (!full_message_id.get_message_id().is_server()) { return promise.set_error(Status::Error(5, "Poll can't be stopped")); } @@ -28384,6 +28394,9 @@ Result MessagesManager::get_invoice_message_id(FullMessageId fu return Status::Error(5, "Message has no invoice"); } auto message_id = full_message_id.get_message_id(); + if (message_id.is_scheduled()) { + return Status::Error(5, "Wrong scheduled message identifier"); + } if (!message_id.is_server()) { return Status::Error(5, "Wrong message identifier"); } @@ -28435,6 +28448,9 @@ void MessagesManager::get_payment_receipt(FullMessageId full_message_id, return promise.set_error(Status::Error(5, "Message has wrong type")); } auto message_id = full_message_id.get_message_id(); + if (message_id.is_scheduled()) { + return promise.set_error(Status::Error(5, "Can't get payment receipt from scheduled messages")); + } if (!message_id.is_server()) { return promise.set_error(Status::Error(5, "Wrong message identifier")); } diff --git a/td/telegram/net/NetQuery.h b/td/telegram/net/NetQuery.h index 4e355b364..70c2533f5 100644 --- a/td/telegram/net/NetQuery.h +++ b/td/telegram/net/NetQuery.h @@ -293,7 +293,7 @@ class NetQuery : public ListNode { static int32 get_my_id(); movable_atomic session_id_{0}; - uint64 message_id_{}; + uint64 message_id_{0}; movable_atomic cancellation_token_{-1}; // == 0 if query is canceled ActorShared callback_;