Partial support for scheduled message IDs.

GitOrigin-RevId: 752336efc26fb73a038801b99b490d0f68163b04
This commit is contained in:
levlam 2019-11-26 23:47:13 +03:00
parent 67e007eebd
commit 6b24886bf0
7 changed files with 36 additions and 1 deletions

View File

@ -241,6 +241,10 @@ int64 CallbackQueriesManager::send_callback_query(FullMessageId full_message_id,
promise.set_error(Status::Error(5, "Message not found")); promise.set_error(Status::Error(5, "Message not found"));
return 0; 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()) { if (!full_message_id.get_message_id().is_server()) {
promise.set_error(Status::Error(5, "Bad message identifier")); promise.set_error(Status::Error(5, "Bad message identifier"));
return 0; return 0;

View File

@ -5274,6 +5274,10 @@ void ContactsManager::report_channel_spam(ChannelId channel_id, UserId user_id,
vector<MessageId> server_message_ids; vector<MessageId> server_message_ids;
for (auto &message_id : 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()) { if (!message_id.is_valid()) {
return promise.set_error(Status::Error(6, "Message not found")); return promise.set_error(Status::Error(6, "Message not found"));
} }

View File

@ -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) { 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()) { switch (content->get_type()) {
case MessageContentType::Poll: case MessageContentType::Poll:
return td->poll_manager_->register_poll(static_cast<const MessagePoll *>(content)->poll_id, full_message_id); return td->poll_manager_->register_poll(static_cast<const MessagePoll *>(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) { 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()) { switch (content->get_type()) {
case MessageContentType::Poll: case MessageContentType::Poll:
return td->poll_manager_->unregister_poll(static_cast<const MessagePoll *>(content)->poll_id, full_message_id); return td->poll_manager_->unregister_poll(static_cast<const MessagePoll *>(content)->poll_id, full_message_id);

View File

@ -64,10 +64,12 @@ MessageType MessageId::get_type() const {
} }
ServerMessageId MessageId::get_server_message_id_force() const { ServerMessageId MessageId::get_server_message_id_force() const {
CHECK(!is_scheduled());
return ServerMessageId(narrow_cast<int32>(id >> SERVER_ID_SHIFT)); return ServerMessageId(narrow_cast<int32>(id >> SERVER_ID_SHIFT));
} }
MessageId MessageId::get_next_message_id(MessageType type) const { MessageId MessageId::get_next_message_id(MessageType type) const {
CHECK(!is_scheduled());
switch (type) { switch (type) {
case MessageType::Server: case MessageType::Server:
return get_next_server_message_id(); return get_next_server_message_id();

View File

@ -43,6 +43,7 @@ class MessageId {
ServerMessageId get_server_message_id_force() const; ServerMessageId get_server_message_id_force() const;
int32 get_scheduled_server_message_id_force() const { int32 get_scheduled_server_message_id_force() const {
CHECK(is_scheduled());
return static_cast<int32>((id >> 3) & ((1 << 18) - 1)); return static_cast<int32>((id >> 3) & ((1 << 18) - 1));
} }
@ -108,11 +109,13 @@ class MessageId {
// returns greatest server message id not bigger than this message id // returns greatest server message id not bigger than this message id
MessageId get_prev_server_message_id() const { MessageId get_prev_server_message_id() const {
CHECK(!is_scheduled());
return MessageId(id & ~FULL_TYPE_MASK); return MessageId(id & ~FULL_TYPE_MASK);
} }
// returns smallest server message id not less than this message id // returns smallest server message id not less than this message id
MessageId get_next_server_message_id() const { MessageId get_next_server_message_id() const {
CHECK(!is_scheduled());
return MessageId((id + FULL_TYPE_MASK) & ~FULL_TYPE_MASK); return MessageId((id + FULL_TYPE_MASK) & ~FULL_TYPE_MASK);
} }

View File

@ -25663,6 +25663,10 @@ bool MessagesManager::update_message_content(DialogId dialog_id, Message *old_me
unique_ptr<MessageContent> new_content, unique_ptr<MessageContent> new_content,
bool need_send_update_message_content, bool need_merge_files, bool need_send_update_message_content, bool need_merge_files,
bool is_message_in_dialog) { bool is_message_in_dialog) {
if (old_message->message_id.is_scheduled()) {
is_message_in_dialog = false;
}
bool is_content_changed = false; bool is_content_changed = false;
bool need_update = false; bool need_update = false;
unique_ptr<MessageContent> &old_content = old_message->content; unique_ptr<MessageContent> &old_content = old_message->content;
@ -28336,6 +28340,9 @@ void MessagesManager::set_poll_answer(FullMessageId full_message_id, vector<int3
if (m->content->get_type() != MessageContentType::Poll) { if (m->content->get_type() != MessageContentType::Poll) {
return promise.set_error(Status::Error(5, "Message is not a 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()) { if (!full_message_id.get_message_id().is_server()) {
return promise.set_error(Status::Error(5, "Poll can't be answered")); 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)) { if (!can_edit_message(full_message_id.get_dialog_id(), m, true)) {
return promise.set_error(Status::Error(5, "Poll can't be stopped")); 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()) { if (!full_message_id.get_message_id().is_server()) {
return promise.set_error(Status::Error(5, "Poll can't be stopped")); return promise.set_error(Status::Error(5, "Poll can't be stopped"));
} }
@ -28384,6 +28394,9 @@ Result<ServerMessageId> MessagesManager::get_invoice_message_id(FullMessageId fu
return Status::Error(5, "Message has no invoice"); return Status::Error(5, "Message has no invoice");
} }
auto message_id = full_message_id.get_message_id(); 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()) { if (!message_id.is_server()) {
return Status::Error(5, "Wrong message identifier"); 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")); return promise.set_error(Status::Error(5, "Message has wrong type"));
} }
auto message_id = full_message_id.get_message_id(); 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()) { if (!message_id.is_server()) {
return promise.set_error(Status::Error(5, "Wrong message identifier")); return promise.set_error(Status::Error(5, "Wrong message identifier"));
} }

View File

@ -293,7 +293,7 @@ class NetQuery : public ListNode {
static int32 get_my_id(); static int32 get_my_id();
movable_atomic<uint64> session_id_{0}; movable_atomic<uint64> session_id_{0};
uint64 message_id_{}; uint64 message_id_{0};
movable_atomic<int32> cancellation_token_{-1}; // == 0 if query is canceled movable_atomic<int32> cancellation_token_{-1}; // == 0 if query is canceled
ActorShared<NetQueryCallback> callback_; ActorShared<NetQueryCallback> callback_;