/* This file is part of Telegram Desktop, the official desktop version of Telegram messaging app, see https://telegram.org Telegram Desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. In addition, as a special exception, the copyright holders give permission to link the code of portions of this program with the OpenSSL library. Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once #include "boxes/peer_list_box.h" #include "mtproto/sender.h" #include "base/weak_unique_ptr.h" namespace Profile { // Viewing admins, banned or restricted users list with search. class ParticipantsBoxController : public PeerListController, private base::Subscriber, private MTP::Sender, public base::enable_weak_from_this { public: enum class Role { Members, Admins, Restricted, Kicked, }; static void Start(not_null channel, Role role); struct Additional { std::map, MTPChannelAdminRights> adminRights; std::set> adminCanEdit; std::map, not_null> adminPromotedBy; std::map, MTPChannelBannedRights> restrictedRights; std::set> kicked; std::map, not_null> restrictedBy; std::set> external; std::set> infoNotLoaded; UserData *creator = nullptr; }; ParticipantsBoxController(not_null channel, Role role); void addNewItem(); void prepare() override; void rowClicked(not_null row) override; void rowActionClicked(not_null row) override; void loadMoreRows() override; void peerListSearchAddRow(not_null peer) override; std::unique_ptr createSearchRow(not_null peer) override; // Callback(not_null) template static void HandleParticipant(const MTPChannelParticipant &participant, Role role, not_null additional, Callback callback); protected: virtual std::unique_ptr createRow(not_null user) const; private: static std::unique_ptr CreateSearchController(not_null channel, Role role, not_null additional); void showAdmin(not_null user); void editAdminDone(not_null user, const MTPChannelAdminRights &rights); void showRestricted(not_null user); void editRestrictedDone(not_null user, const MTPChannelBannedRights &rights); void removeKicked(not_null row, not_null user); void kickMember(not_null user); void kickMemberSure(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(); not_null _channel; Role _role = Role::Admins; int _offset = 0; mtpRequestId _loadRequestId = 0; bool _allLoaded = false; Additional _additional; QPointer _editBox; QPointer _addBox; }; // Members, banned and restricted users server side search. class ParticipantsBoxSearchController : public PeerListSearchController, private MTP::Sender { public: using Role = ParticipantsBoxController::Role; using Additional = ParticipantsBoxController::Additional; ParticipantsBoxSearchController(not_null channel, Role role, not_null additional); void searchQuery(const QString &query) override; bool isLoading() override; bool loadMoreRows() override; private: 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; }; // Adding an admin, banned or restricted user from channel members with search + contacts search + global search. class AddParticipantBoxController : public PeerListController, private base::Subscriber, private MTP::Sender, public base::enable_weak_from_this { public: using Role = ParticipantsBoxController::Role; using Additional = ParticipantsBoxController::Additional; using AdminDoneCallback = base::lambda user, const MTPChannelAdminRights &adminRights)>; using BannedDoneCallback = base::lambda user, const MTPChannelBannedRights &bannedRights)>; AddParticipantBoxController(not_null channel, Role role, AdminDoneCallback adminDoneCallback, BannedDoneCallback bannedDoneCallback); void prepare() override; void rowClicked(not_null row) override; void loadMoreRows() override; std::unique_ptr createSearchRow(not_null peer) override; // Callback(not_null) template static void HandleParticipant(const MTPChannelParticipant &participant, not_null additional, Callback callback); private: template bool checkInfoLoaded(not_null user, Callback callback); void showAdmin(not_null user, bool sure = false); void editAdminDone(not_null user, const MTPChannelAdminRights &rights); void showRestricted(not_null user, bool sure = false); void editRestrictedDone(not_null user, const MTPChannelBannedRights &rights); void kickUser(not_null user, bool sure = false); void restrictUserSure(not_null user, const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights); bool appendRow(not_null user); bool prependRow(not_null user); std::unique_ptr createRow(not_null user) const; not_null _channel; Role _role = Role::Admins; int _offset = 0; mtpRequestId _loadRequestId = 0; bool _allLoaded = false; Additional _additional; QPointer _editBox; AdminDoneCallback _adminDoneCallback; BannedDoneCallback _bannedDoneCallback; }; // Finds channel members, then contacts, then global search results. class AddParticipantBoxSearchController : public PeerListSearchController, private MTP::Sender { public: using Role = ParticipantsBoxController::Role; using Additional = ParticipantsBoxController::Additional; AddParticipantBoxSearchController(not_null channel, not_null additional); void searchQuery(const QString &query) override; bool isLoading() override; bool loadMoreRows() override; private: struct CacheEntry { MTPchannels_ChannelParticipants result; int requestedCount = 0; }; struct Query { QString text; int offset = 0; }; void searchOnServer(); bool searchParticipantsInCache(); void searchParticipantsDone(mtpRequestId requestId, const MTPchannels_ChannelParticipants &result, int requestedCount); bool searchGlobalInCache(); void searchGlobalDone(mtpRequestId requestId, const MTPcontacts_Found &result); void requestParticipants(); void addChatsContacts(); void requestGlobal(); not_null _channel; not_null _additional; base::Timer _timer; QString _query; mtpRequestId _requestId = 0; int _offset = 0; bool _participantsLoaded = false; bool _chatsContactsAdded = false; bool _globalLoaded = false; std::map _participantsCache; std::map _participantsQueries; std::map _globalCache; std::map _globalQueries; }; } // namespace Profile