From 67e007eebd3053e5598eef17539c83593edc6631 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 26 Nov 2019 22:35:16 +0300 Subject: [PATCH] Support scheduled message IDs in logging. GitOrigin-RevId: 4641da410f4cc5c683bfdc2dd67de5dea153fc26 --- td/telegram/MessageId.cpp | 27 ++++++++++++++++++++++----- td/telegram/MessageId.h | 13 +++++++++++-- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/td/telegram/MessageId.cpp b/td/telegram/MessageId.cpp index f321024f..00bf9dac 100644 --- a/td/telegram/MessageId.cpp +++ b/td/telegram/MessageId.cpp @@ -63,8 +63,7 @@ MessageType MessageId::get_type() const { } } -ServerMessageId MessageId::get_server_message_id() const { - CHECK(id == 0 || is_server()); +ServerMessageId MessageId::get_server_message_id_force() const { return ServerMessageId(narrow_cast(id >> SERVER_ID_SHIFT)); } @@ -84,18 +83,36 @@ MessageId MessageId::get_next_message_id(MessageType type) const { } StringBuilder &operator<<(StringBuilder &string_builder, MessageId message_id) { + if (message_id.is_scheduled()) { + string_builder << "scheduled "; + + if (!message_id.is_valid_scheduled()) { + return string_builder << "invalid message " << message_id.get(); + } + if (message_id.is_scheduled_server()) { + return string_builder << "server message " << message_id.get_scheduled_server_message_id_force(); + } + if (message_id.is_local()) { + return string_builder << "local message " << message_id.get_scheduled_server_message_id_force(); + } + if (message_id.is_yet_unsent()) { + return string_builder << "yet unsent message " << message_id.get_scheduled_server_message_id_force(); + } + return string_builder << "bugged message " << message_id.get(); + } + if (!message_id.is_valid()) { return string_builder << "invalid message " << message_id.get(); } if (message_id.is_server()) { - return string_builder << "server message " << (message_id.get() >> MessageId::SERVER_ID_SHIFT); + return string_builder << "server message " << message_id.get_server_message_id_force().get(); } if (message_id.is_local()) { - return string_builder << "local message " << (message_id.get() >> MessageId::SERVER_ID_SHIFT) << '.' + return string_builder << "local message " << message_id.get_server_message_id_force().get() << '.' << (message_id.get() & MessageId::FULL_TYPE_MASK); } if (message_id.is_yet_unsent()) { - return string_builder << "yet unsent message " << (message_id.get() >> MessageId::SERVER_ID_SHIFT) << '.' + return string_builder << "yet unsent message " << message_id.get_server_message_id_force().get() << '.' << (message_id.get() & MessageId::FULL_TYPE_MASK); } return string_builder << "bugged message " << message_id.get(); diff --git a/td/telegram/MessageId.h b/td/telegram/MessageId.h index 98c6eede..f0bc88eb 100644 --- a/td/telegram/MessageId.h +++ b/td/telegram/MessageId.h @@ -40,6 +40,12 @@ class MessageId { // |-------30-------|----18---|1|--2-| // |send_date-2**30 |server_id|1|type| + ServerMessageId get_server_message_id_force() const; + + int32 get_scheduled_server_message_id_force() const { + return static_cast((id >> 3) & ((1 << 18) - 1)); + } + public: MessageId() = default; @@ -95,7 +101,10 @@ class MessageId { return (id & SHORT_TYPE_MASK) == 0; } - ServerMessageId get_server_message_id() const; + ServerMessageId get_server_message_id() const { + CHECK(id == 0 || is_server()); + return get_server_message_id_force(); + } // returns greatest server message id not bigger than this message id MessageId get_prev_server_message_id() const { @@ -111,7 +120,7 @@ class MessageId { int32 get_scheduled_server_message_id() const { CHECK(is_scheduled_server()); - return static_cast((id >> 3) & ((1 << 18) - 1)); + return get_scheduled_server_message_id_force(); } bool operator==(const MessageId &other) const {