1 /* 2 This file is part of Telegram Desktop, 3 the official desktop application for the Telegram messaging service. 4 5 For license and copyright information please follow this link: 6 https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL 7 */ 8 #pragma once 9 10 #include "dialogs/dialogs_indexed_list.h" 11 #include "dialogs/dialogs_pinned_list.h" 12 13 namespace Main { 14 class Session; 15 } // namespace Main 16 17 namespace Dialogs { 18 19 class MainList final { 20 public: 21 MainList( 22 not_null<Main::Session*> session, 23 FilterId filterId, 24 rpl::producer<int> pinnedLimit); 25 26 bool empty() const; 27 bool loaded() const; 28 void setLoaded(bool loaded = true); 29 void setAllAreMuted(bool allAreMuted = true); 30 void clear(); 31 32 RowsByLetter addEntry(const Key &key); 33 void removeEntry(const Key &key); 34 35 void unreadStateChanged( 36 const UnreadState &wasState, 37 const UnreadState &nowState); 38 void unreadEntryChanged( 39 const Dialogs::UnreadState &state, 40 bool added); 41 void updateCloudUnread(const MTPDdialogFolder &data); 42 [[nodiscard]] bool cloudUnreadKnown() const; 43 [[nodiscard]] UnreadState unreadState() const; 44 [[nodiscard]] rpl::producer<UnreadState> unreadStateChanges() const; 45 46 [[nodiscard]] not_null<IndexedList*> indexed(); 47 [[nodiscard]] not_null<const IndexedList*> indexed() const; 48 [[nodiscard]] not_null<PinnedList*> pinned(); 49 [[nodiscard]] not_null<const PinnedList*> pinned() const; 50 51 void setCloudListSize(int size); 52 [[nodiscard]] const rpl::variable<int> &fullSize() const; 53 54 private: 55 void finalizeCloudUnread(); 56 void recomputeFullListSize(); 57 unreadStateChangeNotifier(bool notify)58 auto unreadStateChangeNotifier(bool notify) { 59 const auto wasState = notify ? unreadState() : UnreadState(); 60 return gsl::finally([=] { 61 if (notify) { 62 _unreadStateChanges.fire_copy(wasState); 63 } 64 }); 65 } 66 67 FilterId _filterId = 0; 68 IndexedList _all; 69 PinnedList _pinned; 70 UnreadState _unreadState; 71 UnreadState _cloudUnreadState; 72 rpl::event_stream<UnreadState> _unreadStateChanges; 73 rpl::variable<int> _fullListSize = 0; 74 int _cloudListSize = 0; 75 76 bool _loaded = false; 77 bool _allAreMuted = false; 78 79 rpl::lifetime _lifetime; 80 81 }; 82 83 } // namespace Dialogs 84