diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cc8fd1c3..b5e8f41b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -464,6 +464,7 @@ set(TDLIB_SOURCE td/telegram/DeviceTokenManager.h td/telegram/DhCache.h td/telegram/DhConfig.h + td/telegram/DialogDate.h td/telegram/DialogDb.h td/telegram/DialogId.h td/telegram/DialogParticipant.h diff --git a/td/telegram/DialogDate.h b/td/telegram/DialogDate.h new file mode 100644 index 000000000..49082a1d3 --- /dev/null +++ b/td/telegram/DialogDate.h @@ -0,0 +1,70 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +#include "td/telegram/DialogId.h" +#include "td/telegram/MessageId.h" + +#include "td/utils/StringBuilder.h" + +#include + +namespace td { + +class DialogDate { + int64 order; + DialogId dialog_id; + + public: + DialogDate(int64 order, DialogId dialog_id) : order(order), dialog_id(dialog_id) { + } + + bool operator<(const DialogDate &other) const { + return order > other.order || (order == other.order && dialog_id.get() > other.dialog_id.get()); + } + + bool operator<=(const DialogDate &other) const { + return order >= other.order && (order != other.order || dialog_id.get() >= other.dialog_id.get()); + } + + bool operator==(const DialogDate &other) const { + return order == other.order && dialog_id == other.dialog_id; + } + + bool operator!=(const DialogDate &other) const { + return order != other.order || dialog_id != other.dialog_id; + } + + int64 get_order() const { + return order; + } + DialogId get_dialog_id() const { + return dialog_id; + } + int32 get_date() const { + return static_cast((order >> 32) & 0x7FFFFFFF); + } + MessageId get_message_id() const { + return MessageId(ServerMessageId(static_cast(order & 0x7FFFFFFF))); + } +}; + +const DialogDate MIN_DIALOG_DATE(std::numeric_limits::max(), DialogId()); +const DialogDate MAX_DIALOG_DATE(0, DialogId()); +const int64 DEFAULT_ORDER = -1; + +struct DialogDateHash { + std::size_t operator()(const DialogDate &dialog_date) const { + return std::hash()(dialog_date.get_order()) * 2023654985u + DialogIdHash()(dialog_date.get_dialog_id()); + } +}; + +inline StringBuilder &operator<<(StringBuilder &string_builder, DialogDate dialog_date) { + return string_builder << "[" << dialog_date.get_order() << ", " << dialog_date.get_dialog_id().get() << "]"; +} + +} // namespace td diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 1c7a957d7..e20accf31 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -21,6 +21,7 @@ #include "td/telegram/AccessRights.h" #include "td/telegram/ChannelId.h" #include "td/telegram/Dependencies.h" +#include "td/telegram/DialogDate.h" #include "td/telegram/DialogId.h" #include "td/telegram/DialogParticipant.h" #include "td/telegram/files/FileId.h" @@ -65,62 +66,6 @@ class MultiSequenceDispatcher; class DraftMessage; -class DialogDate { - int64 order; - DialogId dialog_id; - - public: - DialogDate(int64 order, DialogId dialog_id) : order(order), dialog_id(dialog_id) { - } - - bool operator<(const DialogDate &other) const { - return order > other.order || (order == other.order && dialog_id.get() > other.dialog_id.get()); - } - - bool operator<=(const DialogDate &other) const { - return order >= other.order && (order != other.order || dialog_id.get() >= other.dialog_id.get()); - } - - bool operator==(const DialogDate &other) const { - return order == other.order && dialog_id == other.dialog_id; - } - - bool operator!=(const DialogDate &other) const { - return order != other.order || dialog_id != other.dialog_id; - } - - int64 get_order() const { - return order; - } - DialogId get_dialog_id() const { - return dialog_id; - } - int32 get_date() const { - return static_cast((order >> 32) & 0x7FFFFFFF); - } - MessageId get_message_id() const { - return MessageId(ServerMessageId(static_cast(order & 0x7FFFFFFF))); - } - - friend struct DialogDateHash; - - friend StringBuilder &operator<<(StringBuilder &string_builder, DialogDate dialog_date); -}; - -const DialogDate MIN_DIALOG_DATE(std::numeric_limits::max(), DialogId()); -const DialogDate MAX_DIALOG_DATE(0, DialogId()); -const int64 DEFAULT_ORDER = -1; - -struct DialogDateHash { - std::size_t operator()(const DialogDate &dialog_date) const { - return std::hash()(dialog_date.order) * 2023654985u + DialogIdHash()(dialog_date.dialog_id); - } -}; - -inline StringBuilder &operator<<(StringBuilder &string_builder, DialogDate dialog_date) { - return string_builder << "[" << dialog_date.order << ", " << dialog_date.dialog_id.get() << "]"; -} - class dummyUpdate : public telegram_api::Update { public: static constexpr int32 ID = 1234567891;