2021-09-30 06:04:55 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "data/data_peer_id.h"
|
|
|
|
|
|
|
|
struct MsgId {
|
|
|
|
constexpr MsgId() noexcept = default;
|
|
|
|
constexpr MsgId(int64 value) noexcept : bare(value) {
|
|
|
|
}
|
|
|
|
|
2022-10-06 14:45:28 +00:00
|
|
|
friend inline constexpr auto operator<=>(MsgId, MsgId) = default;
|
|
|
|
|
2021-09-30 06:04:55 +00:00
|
|
|
[[nodiscard]] constexpr explicit operator bool() const noexcept {
|
|
|
|
return (bare != 0);
|
|
|
|
}
|
|
|
|
[[nodiscard]] constexpr bool operator!() const noexcept {
|
|
|
|
return !bare;
|
|
|
|
}
|
|
|
|
[[nodiscard]] constexpr MsgId operator-() const noexcept {
|
|
|
|
return -bare;
|
|
|
|
}
|
|
|
|
constexpr MsgId operator++() noexcept {
|
|
|
|
return ++bare;
|
|
|
|
}
|
|
|
|
constexpr MsgId operator++(int) noexcept {
|
|
|
|
return bare++;
|
|
|
|
}
|
|
|
|
constexpr MsgId operator--() noexcept {
|
|
|
|
return --bare;
|
|
|
|
}
|
|
|
|
constexpr MsgId operator--(int) noexcept {
|
|
|
|
return bare--;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64 bare = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(MsgId);
|
|
|
|
|
|
|
|
[[nodiscard]] inline constexpr MsgId operator+(MsgId a, MsgId b) noexcept {
|
|
|
|
return MsgId(a.bare + b.bare);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] inline constexpr MsgId operator-(MsgId a, MsgId b) noexcept {
|
|
|
|
return MsgId(a.bare - b.bare);
|
|
|
|
}
|
|
|
|
|
2021-09-30 15:31:03 +00:00
|
|
|
constexpr auto StartClientMsgId = MsgId(0x01 - (1LL << 58));
|
|
|
|
constexpr auto EndClientMsgId = MsgId(-(1LL << 57));
|
2021-09-30 06:04:55 +00:00
|
|
|
constexpr auto ServerMaxMsgId = MsgId(1LL << 56);
|
2022-03-11 07:04:46 +00:00
|
|
|
constexpr auto ScheduledMsgIdsRange = (1LL << 32);
|
2021-09-30 06:04:55 +00:00
|
|
|
constexpr auto ShowAtUnreadMsgId = MsgId(0);
|
|
|
|
|
2021-09-30 15:31:03 +00:00
|
|
|
constexpr auto SpecialMsgIdShift = EndClientMsgId.bare;
|
|
|
|
constexpr auto ShowAtTheEndMsgId = MsgId(SpecialMsgIdShift + 1);
|
|
|
|
constexpr auto SwitchAtTopMsgId = MsgId(SpecialMsgIdShift + 2);
|
|
|
|
constexpr auto ShowAndStartBotMsgId = MsgId(SpecialMsgIdShift + 4);
|
|
|
|
constexpr auto ShowForChooseMessagesMsgId = MsgId(SpecialMsgIdShift + 6);
|
|
|
|
|
|
|
|
static_assert(SpecialMsgIdShift + 0xFF < 0);
|
|
|
|
static_assert(-(SpecialMsgIdShift + 0xFF) > ServerMaxMsgId);
|
|
|
|
|
2021-09-30 06:04:55 +00:00
|
|
|
[[nodiscard]] constexpr inline bool IsClientMsgId(MsgId id) noexcept {
|
|
|
|
return (id >= StartClientMsgId && id < EndClientMsgId);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] constexpr inline bool IsServerMsgId(MsgId id) noexcept {
|
|
|
|
return (id > 0 && id < ServerMaxMsgId);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct MsgRange {
|
|
|
|
constexpr MsgRange() noexcept = default;
|
|
|
|
constexpr MsgRange(MsgId from, MsgId till) noexcept
|
|
|
|
: from(from)
|
|
|
|
, till(till) {
|
|
|
|
}
|
|
|
|
|
2022-10-06 14:45:28 +00:00
|
|
|
friend inline constexpr bool operator==(MsgRange, MsgRange) = default;
|
|
|
|
|
2021-09-30 06:04:55 +00:00
|
|
|
MsgId from = 0;
|
|
|
|
MsgId till = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FullMsgId {
|
|
|
|
constexpr FullMsgId() noexcept = default;
|
2021-12-09 07:32:54 +00:00
|
|
|
constexpr FullMsgId(PeerId peer, MsgId msg) noexcept
|
|
|
|
: peer(peer), msg(msg) {
|
2021-09-30 06:04:55 +00:00
|
|
|
}
|
2021-12-09 07:32:54 +00:00
|
|
|
FullMsgId(ChannelId channelId, MsgId msgId) = delete;
|
2021-09-30 06:04:55 +00:00
|
|
|
|
2022-10-06 14:45:28 +00:00
|
|
|
friend inline constexpr auto operator<=>(FullMsgId, FullMsgId) = default;
|
|
|
|
|
2021-09-30 06:04:55 +00:00
|
|
|
constexpr explicit operator bool() const noexcept {
|
|
|
|
return msg != 0;
|
|
|
|
}
|
|
|
|
constexpr bool operator!() const noexcept {
|
|
|
|
return msg == 0;
|
|
|
|
}
|
|
|
|
|
2021-12-09 07:32:54 +00:00
|
|
|
PeerId peer = 0;
|
2021-09-30 06:04:55 +00:00
|
|
|
MsgId msg = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(FullMsgId);
|
|
|
|
|
2022-02-24 15:04:24 +00:00
|
|
|
struct GlobalMsgId {
|
|
|
|
FullMsgId itemId;
|
|
|
|
uint64 sessionUniqueId = 0;
|
|
|
|
|
2022-10-06 14:45:28 +00:00
|
|
|
friend inline constexpr auto operator<=>(
|
|
|
|
GlobalMsgId,
|
|
|
|
GlobalMsgId) = default;
|
|
|
|
|
2022-02-24 15:04:24 +00:00
|
|
|
constexpr explicit operator bool() const noexcept {
|
|
|
|
return itemId && sessionUniqueId;
|
|
|
|
}
|
|
|
|
constexpr bool operator!() const noexcept {
|
|
|
|
return !itemId || !sessionUniqueId;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-30 06:04:55 +00:00
|
|
|
namespace std {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct hash<MsgId> : private hash<int64> {
|
|
|
|
size_t operator()(MsgId value) const noexcept {
|
|
|
|
return hash<int64>::operator()(value.bare);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace std
|