info_media_provider.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 "info/media/info_media_common.h"
  9. #include "data/data_shared_media.h"
  10. namespace Info {
  11. class AbstractController;
  12. } // namespace Info
  13. namespace Info::Media {
  14. class Provider final : public ListProvider, private ListSectionDelegate {
  15. public:
  16. explicit Provider(not_null<AbstractController*> controller);
  17. Type type() override;
  18. bool hasSelectRestriction() override;
  19. rpl::producer<bool> hasSelectRestrictionChanges() override;
  20. bool isPossiblyMyItem(not_null<const HistoryItem*> item) override;
  21. std::optional<int> fullCount() override;
  22. void restart() override;
  23. void checkPreload(
  24. QSize viewport,
  25. not_null<BaseLayout*> topLayout,
  26. not_null<BaseLayout*> bottomLayout,
  27. bool preloadTop,
  28. bool preloadBottom) override;
  29. void refreshViewer() override;
  30. rpl::producer<> refreshed() override;
  31. std::vector<ListSection> fillSections(
  32. not_null<Overview::Layout::Delegate*> delegate) override;
  33. rpl::producer<not_null<BaseLayout*>> layoutRemoved() override;
  34. BaseLayout *lookupLayout(const HistoryItem *item) override;
  35. bool isMyItem(not_null<const HistoryItem*> item) override;
  36. bool isAfter(
  37. not_null<const HistoryItem*> a,
  38. not_null<const HistoryItem*> b) override;
  39. void setSearchQuery(QString query) override;
  40. ListItemSelectionData computeSelectionData(
  41. not_null<const HistoryItem*> item,
  42. TextSelection selection) override;
  43. void applyDragSelection(
  44. ListSelectedMap &selected,
  45. not_null<const HistoryItem*> fromItem,
  46. bool skipFrom,
  47. not_null<const HistoryItem*> tillItem,
  48. bool skipTill) override;
  49. bool allowSaveFileAs(
  50. not_null<const HistoryItem*> item,
  51. not_null<DocumentData*> document) override;
  52. QString showInFolderPath(
  53. not_null<const HistoryItem*> item,
  54. not_null<DocumentData*> document) override;
  55. int64 scrollTopStatePosition(not_null<HistoryItem*> item) override;
  56. HistoryItem *scrollTopStateItem(ListScrollTopState state) override;
  57. void saveState(
  58. not_null<Memento*> memento,
  59. ListScrollTopState scrollState) override;
  60. void restoreState(
  61. not_null<Memento*> memento,
  62. Fn<void(ListScrollTopState)> restoreScrollState) override;
  63. private:
  64. static constexpr auto kMinimalIdsLimit = 16;
  65. static constexpr auto kDefaultAroundId = (ServerMaxMsgId - 1);
  66. bool sectionHasFloatingHeader() override;
  67. QString sectionTitle(not_null<const BaseLayout*> item) override;
  68. bool sectionItemBelongsHere(
  69. not_null<const BaseLayout*> item,
  70. not_null<const BaseLayout*> previous) override;
  71. [[nodiscard]] bool isPossiblyMyPeerId(PeerId peerId) const;
  72. [[nodiscard]] FullMsgId computeFullId(UniversalMsgId universalId) const;
  73. [[nodiscard]] BaseLayout *getLayout(
  74. UniversalMsgId universalId,
  75. not_null<Overview::Layout::Delegate*> delegate);
  76. [[nodiscard]] std::unique_ptr<BaseLayout> createLayout(
  77. UniversalMsgId universalId,
  78. not_null<Overview::Layout::Delegate*> delegate,
  79. Type type);
  80. [[nodiscard]] SparseIdsMergedSlice::Key sliceKey(
  81. UniversalMsgId universalId) const;
  82. void itemRemoved(not_null<const HistoryItem*> item);
  83. void markLayoutsStale();
  84. void clearStaleLayouts();
  85. const not_null<AbstractController*> _controller;
  86. const not_null<PeerData*> _peer;
  87. const MsgId _topicRootId = 0;
  88. PeerData * const _migrated = nullptr;
  89. const Type _type = Type::Photo;
  90. UniversalMsgId _universalAroundId = kDefaultAroundId;
  91. int _idsLimit = kMinimalIdsLimit;
  92. SparseIdsMergedSlice _slice;
  93. std::unordered_map<UniversalMsgId, CachedItem> _layouts;
  94. rpl::event_stream<not_null<BaseLayout*>> _layoutRemoved;
  95. rpl::event_stream<> _refreshed;
  96. rpl::lifetime _lifetime;
  97. rpl::lifetime _viewerLifetime;
  98. };
  99. } // namespace Info::Media