/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once #include #include "boxes/peer_list_box.h" #include "mtproto/sender.h" #include "base/timer.h" #include "base/weak_ptr.h" #include "info/profile/info_profile_members_controllers.h" namespace Window { class Navigation; } // namespace Window Fn SaveAdminCallback( not_null peer, not_null user, Fn onDone, Fn onFail); Fn SaveRestrictedCallback( not_null peer, not_null user, Fn onDone, Fn onFail); void SubscribeToMigration( not_null peer, rpl::lifetime &lifetime, Fn)> migrate); enum class ParticipantsRole { Profile, Members, Admins, Restricted, Kicked, }; class ParticipantsOnlineSorter : private base::Subscriber { public: ParticipantsOnlineSorter( not_null peer, not_null delegate); void sort(); rpl::producer onlineCountValue() const; private: void sortDelayed(); void refreshOnlineCount(); not_null _peer; not_null _delegate; base::Timer _sortByOnlineTimer; rpl::variable _onlineCount = 0; }; class ParticipantsAdditionalData { public: using Role = ParticipantsRole; ParticipantsAdditionalData(not_null peer, Role role); UserData *applyParticipant(const MTPChannelParticipant &data); UserData *applyParticipant( const MTPChannelParticipant &data, Role overrideRole); void setExternal(not_null user); void checkForLoaded(not_null user); void fillFromPeer(); [[nodiscard]] bool infoLoaded(not_null user) const; [[nodiscard]] bool canEditAdmin(not_null user) const; [[nodiscard]] bool canAddOrEditAdmin(not_null user) const; [[nodiscard]] bool canRestrictUser(not_null user) const; [[nodiscard]] std::optional adminRights( not_null user) const; [[nodiscard]] std::optional restrictedRights( not_null user) const; [[nodiscard]] bool isCreator(not_null user) const; [[nodiscard]] bool isExternal(not_null user) const; [[nodiscard]] bool isKicked(not_null user) const; [[nodiscard]] UserData *adminPromotedBy(not_null user) const; [[nodiscard]] UserData *restrictedBy(not_null user) const; void migrate(not_null channel); private: UserData *applyCreator(const MTPDchannelParticipantCreator &data); UserData *applyAdmin(const MTPDchannelParticipantAdmin &data); UserData *applyRegular(MTPint userId); UserData *applyBanned(const MTPDchannelParticipantBanned &data); void fillFromChat(not_null chat); void fillFromChannel(not_null channel); not_null _peer; Role _role = Role::Members; UserData *_creator = nullptr; // Data for chats. base::flat_set> _members; base::flat_set> _admins; // Data for channels. base::flat_map, MTPChatAdminRights> _adminRights; base::flat_set> _adminCanEdit; base::flat_map, not_null> _adminPromotedBy; std::map, MTPChatBannedRights> _restrictedRights; std::set> _kicked; std::map, not_null> _restrictedBy; std::set> _external; std::set> _infoNotLoaded; }; // Viewing admins, banned or restricted users list with search. class ParticipantsBoxController : public PeerListController , private base::Subscriber , private MTP::Sender , public base::has_weak_ptr { public: using Role = ParticipantsRole; static void Start( not_null navigation, not_null peer, Role role); ParticipantsBoxController( not_null navigation, not_null peer, Role role); void prepare() override; void rowClicked(not_null row) override; void rowActionClicked(not_null row) override; base::unique_qptr rowContextMenu( QWidget *parent, not_null row) override; void loadMoreRows() override; void peerListSearchAddRow(not_null peer) override; std::unique_ptr createSearchRow( not_null peer) override; std::unique_ptr createRestoredRow( not_null peer) override; std::unique_ptr saveState() const override; void restoreState(std::unique_ptr state) override; rpl::producer onlineCountValue() const override; protected: virtual std::unique_ptr createRow( not_null user) const; private: using Row = Info::Profile::MemberListRow; using Type = Row::Type; using Rights = Row::Rights; struct SavedState : SavedStateBase { explicit SavedState(const ParticipantsAdditionalData &additional); using SearchStateBase = PeerListSearchController::SavedStateBase; std::unique_ptr searchState; int offset = 0; bool allLoaded = false; bool wasLoading = false; ParticipantsAdditionalData additional; rpl::lifetime lifetime; }; static std::unique_ptr CreateSearchController( not_null peer, Role role, not_null additional); void prepareChatRows(not_null chat); void rebuildChatRows(not_null chat); void rebuildChatParticipants(not_null chat); void rebuildChatAdmins(not_null chat); void chatListReady(); void rebuildRowTypes(); void addNewItem(); void addNewParticipants(); void refreshDescription(); void setupListChangeViewers(); void showAdmin(not_null user); void editAdminDone( not_null user, const MTPChatAdminRights &rights); void showRestricted(not_null user); void editRestrictedDone( not_null user, const MTPChatBannedRights &rights); void removeKicked(not_null row, not_null user); void removeKickedWithRow(not_null user); void removeKicked(not_null user); void kickMember(not_null user); void kickMemberSure(not_null user); void unkickMember(not_null user); void removeAdmin(not_null user); void removeAdminSure(not_null user); bool appendRow(not_null user); bool prependRow(not_null user); bool removeRow(not_null user); void refreshCustomStatus(not_null row) const; bool feedMegagroupLastParticipants(); Type computeType(not_null user) const; void recomputeTypeFor(not_null user); void subscribeToMigration(); void migrate(not_null channel); not_null _navigation; not_null _peer; Role _role = Role::Admins; int _offset = 0; mtpRequestId _loadRequestId = 0; bool _allLoaded = false; ParticipantsAdditionalData _additional; std::unique_ptr _onlineSorter; BoxPointer _editBox; BoxPointer _addBox; }; // Members, banned and restricted users server side search. class ParticipantsBoxSearchController : public PeerListSearchController , private MTP::Sender { public: using Role = ParticipantsBoxController::Role; ParticipantsBoxSearchController( not_null channel, Role role, not_null additional); void searchQuery(const QString &query) override; bool isLoading() override; bool loadMoreRows() override; std::unique_ptr saveState() const override; void restoreState(std::unique_ptr state) override; private: struct SavedState : SavedStateBase { QString query; int offset = 0; bool allLoaded = false; bool wasLoading = false; }; struct CacheEntry { MTPchannels_ChannelParticipants result; int requestedCount = 0; }; struct Query { QString text; int offset = 0; }; void searchOnServer(); bool searchInCache(); void searchDone( mtpRequestId requestId, const MTPchannels_ChannelParticipants &result, int requestedCount); not_null _channel; Role _role = Role::Restricted; not_null _additional; base::Timer _timer; QString _query; mtpRequestId _requestId = 0; int _offset = 0; bool _allLoaded = false; std::map _cache; std::map _queries; };