dialogs_main_list.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 "dialogs/dialogs_common.h"
  9. #include "dialogs/dialogs_indexed_list.h"
  10. #include "dialogs/dialogs_pinned_list.h"
  11. namespace Main {
  12. class Session;
  13. } // namespace Main
  14. namespace Data {
  15. class Thread;
  16. } // namespace Data
  17. namespace Dialogs {
  18. class MainList final {
  19. public:
  20. MainList(
  21. not_null<Main::Session*> session,
  22. FilterId filterId,
  23. rpl::producer<int> pinnedLimit);
  24. bool empty() const;
  25. bool loaded() const;
  26. void setLoaded(bool loaded = true);
  27. void setAllAreMuted(bool allAreMuted = true);
  28. void clear();
  29. RowsByLetter addEntry(Key key);
  30. void removeEntry(Key key);
  31. void unreadStateChanged(
  32. const UnreadState &wasState,
  33. const UnreadState &nowState);
  34. void unreadEntryChanged(const UnreadState &state, bool added);
  35. void updateCloudUnread(const MTPDdialogFolder &data);
  36. [[nodiscard]] bool cloudUnreadKnown() const;
  37. [[nodiscard]] UnreadState unreadState() const;
  38. [[nodiscard]] rpl::producer<UnreadState> unreadStateChanges() const;
  39. [[nodiscard]] not_null<IndexedList*> indexed();
  40. [[nodiscard]] not_null<const IndexedList*> indexed() const;
  41. [[nodiscard]] not_null<PinnedList*> pinned();
  42. [[nodiscard]] not_null<const PinnedList*> pinned() const;
  43. void setCloudListSize(int size);
  44. [[nodiscard]] const rpl::variable<int> &fullSize() const;
  45. private:
  46. void finalizeCloudUnread();
  47. void recomputeFullListSize();
  48. inline auto unreadStateChangeNotifier(bool notify);
  49. FilterId _filterId = 0;
  50. IndexedList _all;
  51. PinnedList _pinned;
  52. UnreadState _unreadState;
  53. UnreadState _cloudUnreadState;
  54. rpl::event_stream<UnreadState> _unreadStateChanges;
  55. rpl::variable<int> _fullListSize = 0;
  56. int _cloudListSize = 0;
  57. bool _loaded = false;
  58. bool _allAreMuted = false;
  59. rpl::lifetime _lifetime;
  60. };
  61. auto MainList::unreadStateChangeNotifier(bool notify) {
  62. const auto wasState = notify ? unreadState() : UnreadState();
  63. return gsl::finally([=] {
  64. if (notify) {
  65. _unreadStateChanges.fire_copy(wasState);
  66. }
  67. });
  68. }
  69. } // namespace Dialogs