/* 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 "data/data_chat_participant_status.h" #include "mtproto/sender.h" #include "base/timer.h" class ApiWrap; class ChannelData; namespace Api { class ChatParticipant final { public: enum class Type { Creator, Admin, Member, Restricted, Left, Banned, }; explicit ChatParticipant( const MTPChannelParticipant &p, not_null peer); ChatParticipant( Type type, PeerId peerId, UserId by, ChatRestrictionsInfo restrictions, ChatAdminRightsInfo rights, bool canBeEdited = false, QString rank = QString()); bool isUser() const; bool isCreator() const; bool isCreatorOrAdmin() const; bool isKicked() const; bool canBeEdited() const; UserId by() const; PeerId id() const; UserId userId() const; ChatRestrictionsInfo restrictions() const; ChatAdminRightsInfo rights() const; Type type() const; QString rank() const; void tryApplyCreatorTo(not_null channel) const; private: Type _type = Type::Member; PeerId _peer; UserId _by; // Banned/Restricted/Promoted. bool _canBeEdited = false; QString _rank; ChatRestrictionsInfo _restrictions; ChatAdminRightsInfo _rights; }; class ChatParticipants final { public: struct Parsed { const int availableCount; const std::vector list; }; using TLMembers = MTPDchannels_channelParticipants; using Members = const std::vector &; explicit ChatParticipants(not_null api); void requestLast(not_null channel); void requestBots(not_null channel); void requestAdmins(not_null channel); void requestCountDelayed(not_null channel); static Parsed Parse( not_null channel, const TLMembers &data); static Parsed ParseRecent( not_null channel, const TLMembers &data); void add( not_null peer, const std::vector> &users, Fn done = nullptr); void requestSelf(not_null channel); void requestForAdd( not_null channel, Fn callback); void kick( not_null chat, not_null participant); void kick( not_null channel, not_null participant, ChatRestrictionsInfo currentRights); void unblock( not_null channel, not_null participant); private: MTP::Sender _api; using PeerRequests = base::flat_map; PeerRequests _participantsRequests; PeerRequests _botsRequests; PeerRequests _adminsRequests; base::DelayedCallTimer _participantsCountRequestTimer; struct { ChannelData *channel = nullptr; mtpRequestId requestId = 0; Fn callback; } _forAdd; base::flat_set> _selfParticipantRequests; using KickRequest = std::pair< not_null, not_null>; base::flat_map _kickRequests; }; } // namespace Api