2019-01-10 06:26:08 +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
|
|
|
|
|
|
|
|
#include "boxes/peer_list_controllers.h"
|
|
|
|
#include "boxes/peers/edit_participants_box.h"
|
|
|
|
|
2021-07-08 10:34:06 +00:00
|
|
|
struct ChatAdminRightsInfo;
|
|
|
|
struct ChatRestrictionsInfo;
|
|
|
|
|
2019-07-25 18:55:11 +00:00
|
|
|
namespace Window {
|
|
|
|
class SessionNavigation;
|
|
|
|
} // namespace Window
|
|
|
|
|
2019-01-10 06:26:08 +00:00
|
|
|
class AddParticipantsBoxController : public ContactsBoxController {
|
|
|
|
public:
|
|
|
|
static void Start(
|
2019-07-25 18:55:11 +00:00
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<ChatData*> chat);
|
|
|
|
static void Start(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
|
|
|
not_null<ChannelData*> channel);
|
|
|
|
static void Start(
|
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
2019-01-10 06:26:08 +00:00
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
base::flat_set<not_null<UserData*>> &&alreadyIn);
|
|
|
|
|
2020-12-21 19:43:23 +00:00
|
|
|
explicit AddParticipantsBoxController(not_null<Main::Session*> session);
|
|
|
|
explicit AddParticipantsBoxController(not_null<PeerData*> peer);
|
2019-07-25 18:55:11 +00:00
|
|
|
AddParticipantsBoxController(
|
2019-01-13 13:28:05 +00:00
|
|
|
not_null<PeerData*> peer,
|
2019-01-10 06:26:08 +00:00
|
|
|
base::flat_set<not_null<UserData*>> &&alreadyIn);
|
|
|
|
|
2020-12-21 19:43:23 +00:00
|
|
|
[[nodiscard]] not_null<PeerData*> peer() const {
|
|
|
|
return _peer;
|
|
|
|
}
|
|
|
|
|
2019-01-10 06:26:08 +00:00
|
|
|
void rowClicked(not_null<PeerListRow*> row) override;
|
|
|
|
void itemDeselectedHook(not_null<PeerData*> peer) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void prepareViewHook() override;
|
|
|
|
std::unique_ptr<PeerListRow> createRow(
|
|
|
|
not_null<UserData*> user) override;
|
2021-02-01 18:30:00 +00:00
|
|
|
virtual bool needsInviteLinkButton();
|
2019-01-10 06:26:08 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static void Start(
|
2019-07-25 18:55:11 +00:00
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
2019-01-10 06:26:08 +00:00
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
base::flat_set<not_null<UserData*>> &&alreadyIn,
|
|
|
|
bool justCreated);
|
|
|
|
|
2021-02-01 18:30:00 +00:00
|
|
|
void addInviteLinkButton();
|
2019-01-13 13:28:05 +00:00
|
|
|
bool inviteSelectedUsers(not_null<PeerListBox*> box) const;
|
|
|
|
void subscribeToMigration();
|
2019-01-10 06:26:08 +00:00
|
|
|
int alreadyInCount() const;
|
|
|
|
bool isAlreadyIn(not_null<UserData*> user) const;
|
|
|
|
int fullCount() const;
|
|
|
|
void updateTitle();
|
|
|
|
|
|
|
|
PeerData *_peer = nullptr;
|
|
|
|
base::flat_set<not_null<UserData*>> _alreadyIn;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// Adding an admin, banned or restricted user from channel members
|
|
|
|
// with search + contacts search + global search.
|
|
|
|
class AddSpecialBoxController
|
|
|
|
: public PeerListController
|
|
|
|
, public base::has_weak_ptr {
|
|
|
|
public:
|
|
|
|
using Role = ParticipantsBoxController::Role;
|
|
|
|
|
|
|
|
using AdminDoneCallback = Fn<void(
|
|
|
|
not_null<UserData*> user,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatAdminRightsInfo adminRights,
|
2019-07-19 13:34:09 +00:00
|
|
|
const QString &rank)>;
|
2019-01-10 06:26:08 +00:00
|
|
|
using BannedDoneCallback = Fn<void(
|
2021-03-19 14:01:21 +00:00
|
|
|
not_null<PeerData*> participant,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestrictionsInfo bannedRights)>;
|
2019-01-10 06:26:08 +00:00
|
|
|
AddSpecialBoxController(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
Role role,
|
|
|
|
AdminDoneCallback adminDoneCallback,
|
|
|
|
BannedDoneCallback bannedDoneCallback);
|
|
|
|
|
2020-10-06 12:58:16 +00:00
|
|
|
[[nodiscard]] not_null<PeerData*> peer() const {
|
|
|
|
return _peer;
|
|
|
|
}
|
2019-11-27 08:02:56 +00:00
|
|
|
[[nodiscard]] Main::Session &session() const override;
|
2019-01-10 06:26:08 +00:00
|
|
|
void prepare() override;
|
|
|
|
void rowClicked(not_null<PeerListRow*> row) override;
|
|
|
|
void loadMoreRows() override;
|
|
|
|
|
2019-11-27 08:02:56 +00:00
|
|
|
[[nodiscard]] std::unique_ptr<PeerListRow> createSearchRow(
|
2019-01-10 06:26:08 +00:00
|
|
|
not_null<PeerData*> peer) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
template <typename Callback>
|
2021-03-19 14:01:21 +00:00
|
|
|
bool checkInfoLoaded(not_null<PeerData*> participant, Callback callback);
|
2019-01-10 06:26:08 +00:00
|
|
|
|
|
|
|
void prepareChatRows(not_null<ChatData*> chat);
|
|
|
|
void rebuildChatRows(not_null<ChatData*> chat);
|
|
|
|
|
|
|
|
void showAdmin(not_null<UserData*> user, bool sure = false);
|
|
|
|
void editAdminDone(
|
|
|
|
not_null<UserData*> user,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatAdminRightsInfo rights,
|
2019-07-19 13:34:09 +00:00
|
|
|
const QString &rank);
|
2019-01-10 06:26:08 +00:00
|
|
|
void showRestricted(not_null<UserData*> user, bool sure = false);
|
|
|
|
void editRestrictedDone(
|
2021-03-19 14:01:21 +00:00
|
|
|
not_null<PeerData*> participant,
|
2021-07-08 10:34:06 +00:00
|
|
|
ChatRestrictionsInfo rights);
|
2021-03-19 14:01:21 +00:00
|
|
|
void kickUser(not_null<PeerData*> participant, bool sure = false);
|
|
|
|
bool appendRow(not_null<PeerData*> participant);
|
2019-01-10 06:26:08 +00:00
|
|
|
bool prependRow(not_null<UserData*> user);
|
2021-03-19 14:01:21 +00:00
|
|
|
std::unique_ptr<PeerListRow> createRow(
|
|
|
|
not_null<PeerData*> participant) const;
|
2019-01-10 06:26:08 +00:00
|
|
|
|
2019-01-13 13:28:05 +00:00
|
|
|
void subscribeToMigration();
|
2021-02-12 10:40:55 +00:00
|
|
|
void migrate(not_null<ChatData*> chat, not_null<ChannelData*> channel);
|
2019-01-13 13:28:05 +00:00
|
|
|
|
2019-01-10 06:26:08 +00:00
|
|
|
not_null<PeerData*> _peer;
|
2019-11-27 08:02:56 +00:00
|
|
|
MTP::Sender _api;
|
2019-01-10 06:26:08 +00:00
|
|
|
Role _role = Role::Admins;
|
|
|
|
int _offset = 0;
|
|
|
|
mtpRequestId _loadRequestId = 0;
|
|
|
|
bool _allLoaded = false;
|
2019-01-10 11:01:59 +00:00
|
|
|
ParticipantsAdditionalData _additional;
|
2019-01-10 06:26:08 +00:00
|
|
|
std::unique_ptr<ParticipantsOnlineSorter> _onlineSorter;
|
2019-09-18 11:19:05 +00:00
|
|
|
Ui::BoxPointer _editBox;
|
|
|
|
QPointer<Ui::BoxContent> _editParticipantBox;
|
2019-01-10 06:26:08 +00:00
|
|
|
AdminDoneCallback _adminDoneCallback;
|
|
|
|
BannedDoneCallback _bannedDoneCallback;
|
|
|
|
|
2019-09-09 07:05:29 +00:00
|
|
|
protected:
|
|
|
|
bool _excludeSelf = true;
|
|
|
|
|
2019-01-10 06:26:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Finds chat/channel members, then contacts, then global search results.
|
2021-07-15 11:12:38 +00:00
|
|
|
class AddSpecialBoxSearchController : public PeerListSearchController {
|
2019-01-10 06:26:08 +00:00
|
|
|
public:
|
|
|
|
using Role = ParticipantsBoxController::Role;
|
|
|
|
|
|
|
|
AddSpecialBoxSearchController(
|
|
|
|
not_null<PeerData*> peer,
|
2019-01-10 11:01:59 +00:00
|
|
|
not_null<ParticipantsAdditionalData*> additional);
|
2019-01-10 06:26:08 +00:00
|
|
|
|
|
|
|
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();
|
2019-01-10 13:21:24 +00:00
|
|
|
void addChatMembers(not_null<ChatData*> chat);
|
2019-01-10 06:26:08 +00:00
|
|
|
void addChatsContacts();
|
|
|
|
void requestGlobal();
|
|
|
|
|
2019-01-13 13:28:05 +00:00
|
|
|
void subscribeToMigration();
|
|
|
|
|
2019-01-10 06:26:08 +00:00
|
|
|
not_null<PeerData*> _peer;
|
2019-01-10 11:01:59 +00:00
|
|
|
not_null<ParticipantsAdditionalData*> _additional;
|
2019-11-27 08:02:56 +00:00
|
|
|
MTP::Sender _api;
|
2019-01-10 06:26:08 +00:00
|
|
|
|
|
|
|
base::Timer _timer;
|
|
|
|
QString _query;
|
|
|
|
mtpRequestId _requestId = 0;
|
|
|
|
int _offset = 0;
|
|
|
|
bool _participantsLoaded = false;
|
|
|
|
bool _chatsContactsAdded = false;
|
2019-01-14 13:01:00 +00:00
|
|
|
bool _chatMembersAdded = false;
|
2019-01-10 06:26:08 +00:00
|
|
|
bool _globalLoaded = false;
|
|
|
|
std::map<QString, CacheEntry> _participantsCache;
|
|
|
|
std::map<mtpRequestId, Query> _participantsQueries;
|
|
|
|
std::map<QString, MTPcontacts_Found> _globalCache;
|
|
|
|
std::map<mtpRequestId, QString> _globalQueries;
|
|
|
|
|
|
|
|
};
|