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