data_replies_list.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/weak_ptr.h"
  9. #include "base/timer.h"
  10. class History;
  11. namespace Data {
  12. class ForumTopic;
  13. class Histories;
  14. struct MessagePosition;
  15. struct MessagesSlice;
  16. struct MessageUpdate;
  17. struct TopicUpdate;
  18. struct RepliesReadTillUpdate;
  19. class RepliesList final : public base::has_weak_ptr {
  20. public:
  21. RepliesList(
  22. not_null<History*> history,
  23. MsgId rootId,
  24. ForumTopic *owningTopic = nullptr);
  25. ~RepliesList();
  26. void apply(const RepliesReadTillUpdate &update);
  27. void apply(const MessageUpdate &update);
  28. void apply(const TopicUpdate &update);
  29. void applyDifferenceTooLong();
  30. [[nodiscard]] rpl::producer<MessagesSlice> source(
  31. MessagePosition aroundId,
  32. int limitBefore,
  33. int limitAfter);
  34. [[nodiscard]] rpl::producer<int> fullCount() const;
  35. [[nodiscard]] rpl::producer<std::optional<int>> maybeFullCount() const;
  36. [[nodiscard]] bool unreadCountKnown() const;
  37. [[nodiscard]] int unreadCountCurrent() const;
  38. [[nodiscard]] int displayedUnreadCount() const;
  39. [[nodiscard]] rpl::producer<std::optional<int>> unreadCountValue() const;
  40. void setInboxReadTill(MsgId readTillId, std::optional<int> unreadCount);
  41. [[nodiscard]] MsgId inboxReadTillId() const;
  42. [[nodiscard]] MsgId computeInboxReadTillFull() const;
  43. void setOutboxReadTill(MsgId readTillId);
  44. [[nodiscard]] MsgId computeOutboxReadTillFull() const;
  45. [[nodiscard]] bool isServerSideUnread(
  46. not_null<const HistoryItem*> item) const;
  47. [[nodiscard]] std::optional<int> computeUnreadCountLocally(
  48. MsgId afterId) const;
  49. void requestUnreadCount();
  50. void readTill(not_null<HistoryItem*> item);
  51. void readTill(MsgId tillId);
  52. [[nodiscard]] bool canDeleteMyTopic() const;
  53. [[nodiscard]] rpl::lifetime &lifetime() {
  54. return _lifetime;
  55. }
  56. private:
  57. struct Viewer;
  58. HistoryItem *lookupRoot();
  59. [[nodiscard]] Histories &histories();
  60. void subscribeToUpdates();
  61. void appendClientSideMessages(MessagesSlice &slice);
  62. [[nodiscard]] bool buildFromData(not_null<Viewer*> viewer);
  63. [[nodiscard]] bool applyItemDestroyed(
  64. not_null<Viewer*> viewer,
  65. not_null<HistoryItem*> item);
  66. [[nodiscard]] bool applyUpdate(const MessageUpdate &update);
  67. void applyTopicCreator(PeerId creatorId);
  68. void injectRootMessageAndReverse(not_null<Viewer*> viewer);
  69. void injectRootMessage(not_null<Viewer*> viewer);
  70. void injectRootDivider(
  71. not_null<HistoryItem*> root,
  72. not_null<MessagesSlice*> slice);
  73. bool processMessagesIsEmpty(const MTPmessages_Messages &result);
  74. void loadAround(MsgId id);
  75. void loadBefore();
  76. void loadAfter();
  77. void changeUnreadCountByPost(MsgId id, int delta);
  78. void setUnreadCount(std::optional<int> count);
  79. void readTill(MsgId tillId, HistoryItem *tillIdItem);
  80. void checkReadTillEnd();
  81. void sendReadTillRequest();
  82. void reloadUnreadCountIfNeeded();
  83. const not_null<History*> _history;
  84. ForumTopic *_owningTopic = nullptr;
  85. const MsgId _rootId = 0;
  86. const bool _creating = false;
  87. std::vector<MsgId> _list;
  88. std::optional<int> _skippedBefore;
  89. std::optional<int> _skippedAfter;
  90. rpl::variable<std::optional<int>> _fullCount;
  91. rpl::event_stream<> _listChanges;
  92. rpl::event_stream<> _instantChanges;
  93. std::optional<MsgId> _loadingAround;
  94. rpl::variable<std::optional<int>> _unreadCount;
  95. MsgId _inboxReadTillId = 0;
  96. MsgId _outboxReadTillId = 0;
  97. HistoryItem *_divider = nullptr;
  98. bool _dividerWithComments = false;
  99. int _beforeId = 0;
  100. int _afterId = 0;
  101. base::Timer _readRequestTimer;
  102. mtpRequestId _readRequestId = 0;
  103. mtpRequestId _reloadUnreadCountRequestId = 0;
  104. rpl::lifetime _lifetime;
  105. };
  106. } // namespace Data