2018-09-29 02:39:27 +02:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-09-29 02:39:27 +02:00
|
|
|
//
|
|
|
|
// 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"
|
2019-11-26 17:33:18 +01:00
|
|
|
#include "td/telegram/ServerMessageId.h"
|
2018-09-29 02:39:27 +02:00
|
|
|
|
2022-11-23 17:37:32 +01:00
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/HashTableUtils.h"
|
2018-09-29 02:39:27 +02:00
|
|
|
#include "td/utils/StringBuilder.h"
|
|
|
|
|
2018-09-29 03:41:15 +02:00
|
|
|
#include <limits>
|
2018-09-29 02:39:27 +02:00
|
|
|
|
|
|
|
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<int32>((order >> 32) & 0x7FFFFFFF);
|
|
|
|
}
|
|
|
|
MessageId get_message_id() const {
|
|
|
|
return MessageId(ServerMessageId(static_cast<int32>(order & 0x7FFFFFFF)));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const DialogDate MIN_DIALOG_DATE(std::numeric_limits<int64>::max(), DialogId());
|
|
|
|
const DialogDate MAX_DIALOG_DATE(0, DialogId());
|
|
|
|
const int64 DEFAULT_ORDER = -1;
|
|
|
|
|
|
|
|
struct DialogDateHash {
|
2022-11-23 17:37:32 +01:00
|
|
|
uint32 operator()(const DialogDate &dialog_date) const {
|
2023-07-27 18:05:15 +02:00
|
|
|
return combine_hashes(Hash<int64>()(dialog_date.get_order()), DialogIdHash()(dialog_date.get_dialog_id()));
|
2018-09-29 02:39:27 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
inline StringBuilder &operator<<(StringBuilder &string_builder, DialogDate dialog_date) {
|
|
|
|
return string_builder << "[" << dialog_date.get_order() << ", " << dialog_date.get_dialog_id().get() << "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|