tdesktop/Telegram/SourceFiles/dialogs/dialogs_key.h

124 lines
2.6 KiB
C
Raw Normal View History

/*
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
class History;
2020-06-12 14:09:04 +00:00
class PeerData;
namespace Data {
class Thread;
2019-04-15 11:54:03 +00:00
class Folder;
2022-09-20 18:12:30 +00:00
class ForumTopic;
class SavedSublist;
} // namespace Data
namespace Dialogs {
class Entry;
class Key {
public:
Key() = default;
2020-06-12 14:09:04 +00:00
Key(Entry *entry) : _value(entry) {
}
2020-06-12 14:09:04 +00:00
Key(History *history);
Key(Data::Folder *folder);
Key(Data::Thread *thread);
Key(Data::ForumTopic *topic);
Key(Data::SavedSublist *sublist);
2020-06-12 14:09:04 +00:00
Key(not_null<Entry*> entry) : _value(entry) {
}
2020-06-12 14:09:04 +00:00
Key(not_null<History*> history);
Key(not_null<Data::Thread*> thread);
2020-06-12 14:09:04 +00:00
Key(not_null<Data::Folder*> folder);
Key(not_null<Data::ForumTopic*> topic);
Key(not_null<Data::SavedSublist*> sublist);
explicit operator bool() const {
2020-06-12 14:09:04 +00:00
return (_value != nullptr);
}
[[nodiscard]] not_null<Entry*> entry() const;
[[nodiscard]] History *history() const;
[[nodiscard]] Data::Folder *folder() const;
[[nodiscard]] Data::ForumTopic *topic() const;
[[nodiscard]] Data::Thread *thread() const;
[[nodiscard]] History *owningHistory() const;
[[nodiscard]] PeerData *peer() const;
[[nodiscard]] Data::SavedSublist *sublist() const;
friend inline constexpr auto operator<=>(Key, Key) noexcept = default;
private:
2020-06-12 14:09:04 +00:00
Entry *_value = nullptr;
};
struct RowDescriptor {
RowDescriptor() = default;
RowDescriptor(Key key, FullMsgId fullId) : key(key), fullId(fullId) {
}
Key key;
FullMsgId fullId;
};
inline bool operator==(const RowDescriptor &a, const RowDescriptor &b) {
2018-12-29 13:09:45 +00:00
return (a.key == b.key)
&& ((a.fullId == b.fullId) || (!a.fullId.msg && !b.fullId.msg));
}
inline bool operator!=(const RowDescriptor &a, const RowDescriptor &b) {
return !(a == b);
}
inline bool operator<(const RowDescriptor &a, const RowDescriptor &b) {
if (a.key < b.key) {
return true;
} else if (a.key > b.key) {
return false;
}
return a.fullId < b.fullId;
}
inline bool operator>(const RowDescriptor &a, const RowDescriptor &b) {
return (b < a);
}
inline bool operator<=(const RowDescriptor &a, const RowDescriptor &b) {
return !(b < a);
}
inline bool operator>=(const RowDescriptor &a, const RowDescriptor &b) {
return !(a < b);
}
struct EntryState {
enum class Section {
History,
Profile,
ChatsList,
Scheduled,
Pinned,
Replies,
SavedSublist,
2022-10-14 13:25:05 +00:00
ContextMenu,
ShortcutMessages,
};
Key key;
Section section = Section::History;
FilterId filterId = 0;
2023-10-10 06:49:22 +00:00
FullReplyTo currentReplyTo;
2023-10-11 04:43:32 +00:00
friend inline auto operator<=>(EntryState, EntryState) noexcept
= default;
};
} // namespace Dialogs