info_stories_provider.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "data/data_stories_ids.h"
  10. #include "info/media/info_media_common.h"
  11. class DocumentData;
  12. class HistoryItem;
  13. class PeerData;
  14. class History;
  15. namespace Data {
  16. class Story;
  17. } // namespace Data
  18. namespace Info {
  19. class AbstractController;
  20. } // namespace Info
  21. namespace Info::Stories {
  22. enum class Tab;
  23. class Provider final
  24. : public Media::ListProvider
  25. , private Media::ListSectionDelegate
  26. , public base::has_weak_ptr {
  27. public:
  28. explicit Provider(not_null<AbstractController*> controller);
  29. ~Provider();
  30. Media::Type type() override;
  31. bool hasSelectRestriction() override;
  32. rpl::producer<bool> hasSelectRestrictionChanges() override;
  33. bool isPossiblyMyItem(not_null<const HistoryItem*> item) override;
  34. std::optional<int> fullCount() override;
  35. void restart() override;
  36. void checkPreload(
  37. QSize viewport,
  38. not_null<Media::BaseLayout*> topLayout,
  39. not_null<Media::BaseLayout*> bottomLayout,
  40. bool preloadTop,
  41. bool preloadBottom) override;
  42. void refreshViewer() override;
  43. rpl::producer<> refreshed() override;
  44. void setSearchQuery(QString query) override;
  45. std::vector<Media::ListSection> fillSections(
  46. not_null<Overview::Layout::Delegate*> delegate) override;
  47. rpl::producer<not_null<Media::BaseLayout*>> layoutRemoved() override;
  48. Media::BaseLayout *lookupLayout(const HistoryItem *item) override;
  49. bool isMyItem(not_null<const HistoryItem*> item) override;
  50. bool isAfter(
  51. not_null<const HistoryItem*> a,
  52. not_null<const HistoryItem*> b) override;
  53. Media::ListItemSelectionData computeSelectionData(
  54. not_null<const HistoryItem*> item,
  55. TextSelection selection) override;
  56. void applyDragSelection(
  57. Media::ListSelectedMap &selected,
  58. not_null<const HistoryItem*> fromItem,
  59. bool skipFrom,
  60. not_null<const HistoryItem*> tillItem,
  61. bool skipTill) override;
  62. bool allowSaveFileAs(
  63. not_null<const HistoryItem*> item,
  64. not_null<DocumentData*> document) override;
  65. QString showInFolderPath(
  66. not_null<const HistoryItem*> item,
  67. not_null<DocumentData*> document) override;
  68. int64 scrollTopStatePosition(not_null<HistoryItem*> item) override;
  69. HistoryItem *scrollTopStateItem(
  70. Media::ListScrollTopState state) override;
  71. void saveState(
  72. not_null<Media::Memento*> memento,
  73. Media::ListScrollTopState scrollState) override;
  74. void restoreState(
  75. not_null<Media::Memento*> memento,
  76. Fn<void(Media::ListScrollTopState)> restoreScrollState) override;
  77. private:
  78. static constexpr auto kMinimalIdsLimit = 16;
  79. static constexpr auto kDefaultAroundId = ServerMaxStoryId - 1;
  80. bool sectionHasFloatingHeader() override;
  81. QString sectionTitle(not_null<const Media::BaseLayout*> item) override;
  82. bool sectionItemBelongsHere(
  83. not_null<const Media::BaseLayout*> item,
  84. not_null<const Media::BaseLayout*> previous) override;
  85. void storyRemoved(not_null<Data::Story*> story);
  86. void markLayoutsStale();
  87. void clearStaleLayouts();
  88. void clear();
  89. [[nodiscard]] HistoryItem *ensureItem(StoryId id);
  90. [[nodiscard]] Media::BaseLayout *getLayout(
  91. StoryId id,
  92. not_null<Overview::Layout::Delegate*> delegate);
  93. [[nodiscard]] std::unique_ptr<Media::BaseLayout> createLayout(
  94. StoryId id,
  95. not_null<Overview::Layout::Delegate*> delegate);
  96. const not_null<AbstractController*> _controller;
  97. const not_null<PeerData*> _peer;
  98. const not_null<History*> _history;
  99. const Tab _tab;
  100. StoryId _aroundId = kDefaultAroundId;
  101. int _idsLimit = kMinimalIdsLimit;
  102. Data::StoriesIdsSlice _slice;
  103. base::flat_map<StoryId, std::shared_ptr<HistoryItem>> _items;
  104. std::unordered_map<StoryId, Media::CachedItem> _layouts;
  105. rpl::event_stream<not_null<Media::BaseLayout*>> _layoutRemoved;
  106. rpl::event_stream<> _refreshed;
  107. bool _started = false;
  108. rpl::lifetime _lifetime;
  109. rpl::lifetime _viewerLifetime;
  110. };
  111. } // namespace Info::Stories