data_thread.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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/flags.h"
  9. #include "dialogs/dialogs_entry.h"
  10. #include "dialogs/ui/dialogs_message_view.h"
  11. #include "ui/text/text.h"
  12. #include <deque>
  13. enum class ChatRestriction;
  14. using ChatRestrictions = base::flags<ChatRestriction>;
  15. namespace Main {
  16. class Session;
  17. } // namespace Main
  18. namespace HistoryUnreadThings {
  19. enum class AddType;
  20. struct All;
  21. class Proxy;
  22. class ConstProxy;
  23. } // namespace HistoryUnreadThings
  24. namespace HistoryView {
  25. class SendActionPainter;
  26. } // namespace HistoryView
  27. namespace st {
  28. extern const int &dialogsTextWidthMin;
  29. } // namespace st
  30. namespace Data {
  31. class PeerNotifySettings;
  32. enum class ItemNotificationType {
  33. Message,
  34. Reaction,
  35. };
  36. struct ItemNotification {
  37. not_null<HistoryItem*> item;
  38. UserData *reactionSender = nullptr;
  39. ItemNotificationType type = ItemNotificationType::Message;
  40. friend inline auto operator<=>(
  41. ItemNotification a,
  42. ItemNotification b) = default;
  43. };
  44. class Thread : public Dialogs::Entry {
  45. public:
  46. using Entry::Entry;
  47. ~Thread();
  48. [[nodiscard]] virtual not_null<History*> owningHistory() = 0;
  49. [[nodiscard]] not_null<Thread*> migrateToOrMe() const;
  50. [[nodiscard]] not_null<const History*> owningHistory() const {
  51. return const_cast<Thread*>(this)->owningHistory();
  52. }
  53. [[nodiscard]] MsgId topicRootId() const;
  54. [[nodiscard]] not_null<PeerData*> peer() const;
  55. [[nodiscard]] PeerNotifySettings &notify();
  56. [[nodiscard]] const PeerNotifySettings &notify() const;
  57. void setUnreadThingsKnown();
  58. [[nodiscard]] HistoryUnreadThings::Proxy unreadMentions();
  59. [[nodiscard]] HistoryUnreadThings::ConstProxy unreadMentions() const;
  60. [[nodiscard]] HistoryUnreadThings::Proxy unreadReactions();
  61. [[nodiscard]] HistoryUnreadThings::ConstProxy unreadReactions() const;
  62. virtual void hasUnreadMentionChanged(bool has) = 0;
  63. virtual void hasUnreadReactionChanged(bool has) = 0;
  64. void removeNotification(not_null<HistoryItem*> item);
  65. void clearNotifications();
  66. void clearIncomingNotifications();
  67. [[nodiscard]] auto currentNotification() const
  68. -> std::optional<ItemNotification>;
  69. bool hasNotification() const;
  70. void skipNotification();
  71. void pushNotification(ItemNotification notification);
  72. void popNotification(ItemNotification notification);
  73. [[nodiscard]] bool muted() const {
  74. return (_flags & Flag::Muted);
  75. }
  76. virtual void setMuted(bool muted);
  77. [[nodiscard]] bool unreadMark() const {
  78. return (_flags & Flag::UnreadMark);
  79. }
  80. [[nodiscard]] virtual bool isServerSideUnread(
  81. not_null<const HistoryItem*> item) const = 0;
  82. [[nodiscard]] const base::flat_set<MsgId> &unreadMentionsIds() const;
  83. [[nodiscard]] const base::flat_set<MsgId> &unreadReactionsIds() const;
  84. [[nodiscard]] Ui::Text::String &cloudDraftTextCache() {
  85. return _cloudDraftTextCache;
  86. }
  87. [[nodiscard]] Dialogs::Ui::MessageView &lastItemDialogsView() {
  88. return _lastItemDialogsView;
  89. }
  90. [[nodiscard]] virtual auto sendActionPainter()
  91. -> not_null<HistoryView::SendActionPainter*> = 0;
  92. [[nodiscard]] bool hasPinnedMessages() const;
  93. void setHasPinnedMessages(bool has);
  94. protected:
  95. void setUnreadMarkFlag(bool unread);
  96. private:
  97. enum class Flag : uchar {
  98. UnreadMark = (1 << 0),
  99. Muted = (1 << 1),
  100. UnreadThingsKnown = (1 << 2),
  101. HasPinnedMessages = (1 << 3),
  102. };
  103. friend inline constexpr bool is_flag_type(Flag) { return true; }
  104. Ui::Text::String _cloudDraftTextCache = { st::dialogsTextWidthMin };
  105. Dialogs::Ui::MessageView _lastItemDialogsView;
  106. std::unique_ptr<HistoryUnreadThings::All> _unreadThings;
  107. std::deque<ItemNotification> _notifications;
  108. base::flags<Flag> _flags;
  109. };
  110. } // namespace Data