dialogs_key.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "base/qt/qt_compare.h"
  9. #include "data/data_message_reaction_id.h"
  10. class History;
  11. class PeerData;
  12. namespace Data {
  13. class Thread;
  14. class Folder;
  15. class ForumTopic;
  16. class SavedSublist;
  17. struct ReactionId;
  18. } // namespace Data
  19. namespace Dialogs {
  20. class Entry;
  21. enum class ChatSearchTab : uchar;
  22. class Key {
  23. public:
  24. Key() = default;
  25. Key(Entry *entry) : _value(entry) {
  26. }
  27. Key(History *history);
  28. Key(Data::Folder *folder);
  29. Key(Data::Thread *thread);
  30. Key(Data::ForumTopic *topic);
  31. Key(Data::SavedSublist *sublist);
  32. Key(not_null<Entry*> entry) : _value(entry) {
  33. }
  34. Key(not_null<History*> history);
  35. Key(not_null<Data::Thread*> thread);
  36. Key(not_null<Data::Folder*> folder);
  37. Key(not_null<Data::ForumTopic*> topic);
  38. Key(not_null<Data::SavedSublist*> sublist);
  39. explicit operator bool() const {
  40. return (_value != nullptr);
  41. }
  42. [[nodiscard]] not_null<Entry*> entry() const;
  43. [[nodiscard]] History *history() const;
  44. [[nodiscard]] Data::Folder *folder() const;
  45. [[nodiscard]] Data::ForumTopic *topic() const;
  46. [[nodiscard]] Data::Thread *thread() const;
  47. [[nodiscard]] History *owningHistory() const;
  48. [[nodiscard]] PeerData *peer() const;
  49. [[nodiscard]] Data::SavedSublist *sublist() const;
  50. friend inline constexpr auto operator<=>(Key, Key) noexcept = default;
  51. private:
  52. Entry *_value = nullptr;
  53. };
  54. struct RowDescriptor {
  55. RowDescriptor() = default;
  56. RowDescriptor(Key key, FullMsgId fullId) : key(key), fullId(fullId) {
  57. }
  58. Key key;
  59. FullMsgId fullId;
  60. };
  61. inline bool operator==(const RowDescriptor &a, const RowDescriptor &b) {
  62. return (a.key == b.key)
  63. && ((a.fullId == b.fullId) || (!a.fullId.msg && !b.fullId.msg));
  64. }
  65. inline bool operator!=(const RowDescriptor &a, const RowDescriptor &b) {
  66. return !(a == b);
  67. }
  68. inline bool operator<(const RowDescriptor &a, const RowDescriptor &b) {
  69. if (a.key < b.key) {
  70. return true;
  71. } else if (a.key > b.key) {
  72. return false;
  73. }
  74. return a.fullId < b.fullId;
  75. }
  76. inline bool operator>(const RowDescriptor &a, const RowDescriptor &b) {
  77. return (b < a);
  78. }
  79. inline bool operator<=(const RowDescriptor &a, const RowDescriptor &b) {
  80. return !(b < a);
  81. }
  82. inline bool operator>=(const RowDescriptor &a, const RowDescriptor &b) {
  83. return !(a < b);
  84. }
  85. struct EntryState {
  86. enum class Section {
  87. History,
  88. Profile,
  89. ChatsList,
  90. Scheduled,
  91. Pinned,
  92. Replies,
  93. SavedSublist,
  94. ContextMenu,
  95. ShortcutMessages,
  96. };
  97. Key key;
  98. Section section = Section::History;
  99. FilterId filterId = 0;
  100. FullReplyTo currentReplyTo;
  101. friend inline auto operator<=>(
  102. const EntryState&,
  103. const EntryState&) = default;
  104. friend inline bool operator==(
  105. const EntryState&,
  106. const EntryState&) = default;
  107. };
  108. enum class ChatTypeFilter : uchar {
  109. All,
  110. Private,
  111. Groups,
  112. Channels,
  113. };
  114. struct SearchState {
  115. Key inChat;
  116. PeerData *fromPeer = nullptr;
  117. std::vector<Data::ReactionId> tags;
  118. ChatSearchTab tab = {};
  119. ChatTypeFilter filter = ChatTypeFilter::All;
  120. QString query;
  121. [[nodiscard]] bool empty() const;
  122. [[nodiscard]] ChatSearchTab defaultTabForMe() const;
  123. [[nodiscard]] bool filterChatsList() const;
  124. explicit operator bool() const {
  125. return !empty();
  126. }
  127. friend inline auto operator<=>(
  128. const SearchState&,
  129. const SearchState&) noexcept = default;
  130. friend inline bool operator==(
  131. const SearchState&,
  132. const SearchState&) = default;
  133. };
  134. } // namespace Dialogs