2017-06-16 11:05:13 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-06-16 11:05:13 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-06-16 11:05:13 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-10-22 12:07:57 +00:00
|
|
|
#include <rpl/variable.h>
|
2017-06-16 11:05:13 +00:00
|
|
|
#include "boxes/peer_list_box.h"
|
|
|
|
#include "mtproto/sender.h"
|
2017-09-26 18:44:58 +00:00
|
|
|
#include "base/timer.h"
|
2017-11-30 17:33:27 +00:00
|
|
|
#include "base/weak_ptr.h"
|
2017-11-07 17:53:00 +00:00
|
|
|
#include "info/profile/info_profile_members_controllers.h"
|
2017-06-16 11:05:13 +00:00
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
namespace Window {
|
2017-12-04 07:33:33 +00:00
|
|
|
class Navigation;
|
2017-10-03 13:05:58 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
2017-06-16 11:05:13 +00:00
|
|
|
namespace Profile {
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(
|
2019-01-03 14:39:19 +00:00
|
|
|
const MTPChatAdminRights &oldRights,
|
|
|
|
const MTPChatAdminRights &newRights)> SaveAdminCallback(
|
2018-05-18 14:16:14 +00:00
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
not_null<UserData*> user,
|
2019-01-03 14:39:19 +00:00
|
|
|
Fn<void(const MTPChatAdminRights &newRights)> onDone,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> onFail);
|
2018-05-18 14:16:14 +00:00
|
|
|
|
2017-06-16 11:05:13 +00:00
|
|
|
// Viewing admins, banned or restricted users list with search.
|
2017-09-26 17:57:01 +00:00
|
|
|
class ParticipantsBoxController
|
|
|
|
: public PeerListController
|
|
|
|
, private base::Subscriber
|
|
|
|
, private MTP::Sender
|
2017-11-30 17:33:27 +00:00
|
|
|
, public base::has_weak_ptr {
|
2017-06-16 11:05:13 +00:00
|
|
|
public:
|
|
|
|
enum class Role {
|
2017-09-26 17:57:01 +00:00
|
|
|
Profile,
|
2017-07-10 16:13:40 +00:00
|
|
|
Members,
|
2017-06-16 11:05:13 +00:00
|
|
|
Admins,
|
|
|
|
Restricted,
|
|
|
|
Kicked,
|
|
|
|
};
|
2017-10-03 13:05:58 +00:00
|
|
|
static void Start(
|
2017-12-04 07:33:33 +00:00
|
|
|
not_null<Window::Navigation*> navigation,
|
2017-10-03 13:05:58 +00:00
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
Role role);
|
2017-06-16 11:05:13 +00:00
|
|
|
|
|
|
|
struct Additional {
|
2019-01-03 14:39:19 +00:00
|
|
|
std::map<not_null<UserData*>, MTPChatAdminRights> adminRights;
|
2017-08-17 08:31:24 +00:00
|
|
|
std::set<not_null<UserData*>> adminCanEdit;
|
|
|
|
std::map<not_null<UserData*>, not_null<UserData*>> adminPromotedBy;
|
2019-01-03 14:39:19 +00:00
|
|
|
std::map<not_null<UserData*>, MTPChatBannedRights> restrictedRights;
|
2017-08-17 08:31:24 +00:00
|
|
|
std::set<not_null<UserData*>> kicked;
|
|
|
|
std::map<not_null<UserData*>, not_null<UserData*>> restrictedBy;
|
|
|
|
std::set<not_null<UserData*>> external;
|
|
|
|
std::set<not_null<UserData*>> infoNotLoaded;
|
2017-06-16 11:05:13 +00:00
|
|
|
UserData *creator = nullptr;
|
|
|
|
};
|
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
ParticipantsBoxController(
|
2017-12-04 07:33:33 +00:00
|
|
|
not_null<Window::Navigation*> navigation,
|
2017-10-03 13:05:58 +00:00
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
Role role);
|
2017-06-16 11:05:13 +00:00
|
|
|
|
|
|
|
void addNewItem();
|
|
|
|
|
|
|
|
void prepare() override;
|
2017-08-17 08:31:24 +00:00
|
|
|
void rowClicked(not_null<PeerListRow*> row) override;
|
|
|
|
void rowActionClicked(not_null<PeerListRow*> row) override;
|
2018-02-12 11:10:40 +00:00
|
|
|
base::unique_qptr<Ui::PopupMenu> rowContextMenu(
|
2018-07-19 14:27:09 +00:00
|
|
|
QWidget *parent,
|
2017-10-22 17:06:57 +00:00
|
|
|
not_null<PeerListRow*> row) override;
|
2017-06-16 11:05:13 +00:00
|
|
|
void loadMoreRows() override;
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void peerListSearchAddRow(not_null<PeerData*> peer) override;
|
2017-10-24 17:11:35 +00:00
|
|
|
std::unique_ptr<PeerListRow> createSearchRow(
|
|
|
|
not_null<PeerData*> peer) override;
|
|
|
|
std::unique_ptr<PeerListRow> createRestoredRow(
|
|
|
|
not_null<PeerData*> peer) override;
|
|
|
|
|
2017-12-04 12:08:43 +00:00
|
|
|
std::unique_ptr<PeerListState> saveState() const override;
|
2017-10-24 17:11:35 +00:00
|
|
|
void restoreState(std::unique_ptr<PeerListState> state) override;
|
2017-06-16 11:05:13 +00:00
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
// Callback(not_null<UserData*>)
|
2017-06-16 11:05:13 +00:00
|
|
|
template <typename Callback>
|
2017-10-24 17:11:35 +00:00
|
|
|
static void HandleParticipant(
|
|
|
|
const MTPChannelParticipant &participant,
|
|
|
|
Role role,
|
|
|
|
not_null<Additional*> additional,
|
|
|
|
Callback callback);
|
2017-06-16 11:05:13 +00:00
|
|
|
|
2017-11-21 09:20:56 +00:00
|
|
|
rpl::producer<int> onlineCountValue() const override;
|
2017-10-22 12:07:57 +00:00
|
|
|
|
2017-08-01 15:55:51 +00:00
|
|
|
protected:
|
2017-08-17 08:31:24 +00:00
|
|
|
virtual std::unique_ptr<PeerListRow> createRow(not_null<UserData*> user) const;
|
2017-08-01 15:55:51 +00:00
|
|
|
|
2017-06-16 11:05:13 +00:00
|
|
|
private:
|
2017-11-07 17:53:00 +00:00
|
|
|
using Row = Info::Profile::MemberListRow;
|
|
|
|
using Type = Row::Type;
|
|
|
|
using Rights = Row::Rights;
|
2017-10-25 08:38:55 +00:00
|
|
|
struct SavedState : SavedStateBase {
|
|
|
|
std::unique_ptr<PeerListSearchController::SavedStateBase> searchState;
|
2017-10-24 17:11:35 +00:00
|
|
|
int offset = 0;
|
|
|
|
bool allLoaded = false;
|
|
|
|
bool wasLoading = false;
|
|
|
|
Additional additional;
|
|
|
|
rpl::lifetime lifetime;
|
|
|
|
};
|
2017-11-07 17:53:00 +00:00
|
|
|
|
2017-10-24 17:11:35 +00:00
|
|
|
static std::unique_ptr<PeerListSearchController> CreateSearchController(
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
Role role,
|
|
|
|
not_null<Additional*> additional);
|
2017-08-17 08:31:24 +00:00
|
|
|
|
2017-11-10 15:45:10 +00:00
|
|
|
void setNonEmptyDescription();
|
2017-09-26 18:44:58 +00:00
|
|
|
void setupSortByOnline();
|
2017-10-22 17:06:57 +00:00
|
|
|
void setupListChangeViewers();
|
2017-09-26 18:44:58 +00:00
|
|
|
void sortByOnlineDelayed();
|
|
|
|
void sortByOnline();
|
2017-08-17 08:31:24 +00:00
|
|
|
void showAdmin(not_null<UserData*> user);
|
2017-12-26 16:12:10 +00:00
|
|
|
void editAdminDone(
|
|
|
|
not_null<UserData*> user,
|
2019-01-03 14:39:19 +00:00
|
|
|
const MTPChatAdminRights &rights);
|
2017-08-17 08:31:24 +00:00
|
|
|
void showRestricted(not_null<UserData*> user);
|
2017-12-26 16:12:10 +00:00
|
|
|
void editRestrictedDone(
|
|
|
|
not_null<UserData*> user,
|
2019-01-03 14:39:19 +00:00
|
|
|
const MTPChatBannedRights &rights);
|
2017-08-17 08:31:24 +00:00
|
|
|
void removeKicked(not_null<PeerListRow*> row, not_null<UserData*> user);
|
|
|
|
void kickMember(not_null<UserData*> user);
|
|
|
|
void kickMemberSure(not_null<UserData*> user);
|
2017-12-26 14:01:48 +00:00
|
|
|
void removeAdmin(not_null<UserData*> user);
|
|
|
|
void removeAdminSure(not_null<UserData*> user);
|
2017-08-17 08:31:24 +00:00
|
|
|
bool appendRow(not_null<UserData*> user);
|
|
|
|
bool prependRow(not_null<UserData*> user);
|
|
|
|
bool removeRow(not_null<UserData*> user);
|
|
|
|
void refreshCustomStatus(not_null<PeerListRow*> row) const;
|
2017-07-10 16:13:40 +00:00
|
|
|
bool feedMegagroupLastParticipants();
|
2017-10-22 12:07:57 +00:00
|
|
|
void refreshOnlineCount();
|
2017-11-07 17:53:00 +00:00
|
|
|
Type computeType(not_null<UserData*> user) const;
|
|
|
|
void recomputeTypeFor(not_null<UserData*> user);
|
|
|
|
bool canEditAdmin(not_null<UserData*> user) const;
|
|
|
|
bool canRestrictUser(not_null<UserData*> user) const;
|
|
|
|
bool canEditAdminByRights(not_null<UserData*> user) const;
|
2017-06-16 11:05:13 +00:00
|
|
|
|
2017-12-04 07:33:33 +00:00
|
|
|
not_null<Window::Navigation*> _navigation;
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<ChannelData*> _channel;
|
2017-06-16 11:05:13 +00:00
|
|
|
Role _role = Role::Admins;
|
|
|
|
int _offset = 0;
|
|
|
|
mtpRequestId _loadRequestId = 0;
|
|
|
|
bool _allLoaded = false;
|
|
|
|
Additional _additional;
|
|
|
|
QPointer<BoxContent> _editBox;
|
|
|
|
QPointer<PeerListBox> _addBox;
|
|
|
|
|
2017-09-26 18:44:58 +00:00
|
|
|
base::Timer _sortByOnlineTimer;
|
2017-10-22 12:07:57 +00:00
|
|
|
rpl::variable<int> _onlineCount = 0;
|
2017-09-26 18:44:58 +00:00
|
|
|
|
2017-06-16 11:05:13 +00:00
|
|
|
};
|
|
|
|
|
2017-07-10 16:13:40 +00:00
|
|
|
// Members, banned and restricted users server side search.
|
2017-10-25 08:38:55 +00:00
|
|
|
class ParticipantsBoxSearchController
|
|
|
|
: public PeerListSearchController
|
|
|
|
, private MTP::Sender {
|
2017-06-16 11:05:13 +00:00
|
|
|
public:
|
|
|
|
using Role = ParticipantsBoxController::Role;
|
|
|
|
using Additional = ParticipantsBoxController::Additional;
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
ParticipantsBoxSearchController(not_null<ChannelData*> channel, Role role, not_null<Additional*> additional);
|
2017-06-16 11:05:13 +00:00
|
|
|
|
|
|
|
void searchQuery(const QString &query) override;
|
|
|
|
bool isLoading() override;
|
|
|
|
bool loadMoreRows() override;
|
|
|
|
|
2017-12-04 12:08:43 +00:00
|
|
|
std::unique_ptr<SavedStateBase> saveState() const override;
|
2017-10-25 08:38:55 +00:00
|
|
|
void restoreState(std::unique_ptr<SavedStateBase> state) override;
|
2017-10-24 17:11:35 +00:00
|
|
|
|
2017-06-16 11:05:13 +00:00
|
|
|
private:
|
2017-10-25 08:38:55 +00:00
|
|
|
struct SavedState : SavedStateBase {
|
2017-10-24 17:11:35 +00:00
|
|
|
QString query;
|
|
|
|
int offset = 0;
|
|
|
|
bool allLoaded = false;
|
|
|
|
bool wasLoading = false;
|
|
|
|
};
|
2017-06-16 11:05:13 +00:00
|
|
|
struct CacheEntry {
|
|
|
|
MTPchannels_ChannelParticipants result;
|
|
|
|
int requestedCount = 0;
|
|
|
|
};
|
|
|
|
struct Query {
|
|
|
|
QString text;
|
|
|
|
int offset = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void searchOnServer();
|
|
|
|
bool searchInCache();
|
2017-10-24 17:11:35 +00:00
|
|
|
void searchDone(
|
|
|
|
mtpRequestId requestId,
|
|
|
|
const MTPchannels_ChannelParticipants &result,
|
|
|
|
int requestedCount);
|
2017-06-16 11:05:13 +00:00
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<ChannelData*> _channel;
|
2017-06-16 11:05:13 +00:00
|
|
|
Role _role = Role::Restricted;
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<Additional*> _additional;
|
2017-06-16 11:05:13 +00:00
|
|
|
|
|
|
|
base::Timer _timer;
|
|
|
|
QString _query;
|
|
|
|
mtpRequestId _requestId = 0;
|
|
|
|
int _offset = 0;
|
|
|
|
bool _allLoaded = false;
|
|
|
|
std::map<QString, CacheEntry> _cache;
|
|
|
|
std::map<mtpRequestId, Query> _queries;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// Adding an admin, banned or restricted user from channel members with search + contacts search + global search.
|
2017-11-30 17:33:27 +00:00
|
|
|
class AddParticipantBoxController : public PeerListController, private base::Subscriber, private MTP::Sender, public base::has_weak_ptr {
|
2017-06-16 11:05:13 +00:00
|
|
|
public:
|
|
|
|
using Role = ParticipantsBoxController::Role;
|
|
|
|
using Additional = ParticipantsBoxController::Additional;
|
|
|
|
|
2019-01-03 14:39:19 +00:00
|
|
|
using AdminDoneCallback = Fn<void(not_null<UserData*> user, const MTPChatAdminRights &adminRights)>;
|
|
|
|
using BannedDoneCallback = Fn<void(not_null<UserData*> user, const MTPChatBannedRights &bannedRights)>;
|
2017-08-17 08:31:24 +00:00
|
|
|
AddParticipantBoxController(not_null<ChannelData*> channel, Role role, AdminDoneCallback adminDoneCallback, BannedDoneCallback bannedDoneCallback);
|
2017-06-16 11:05:13 +00:00
|
|
|
|
|
|
|
void prepare() override;
|
2017-08-17 08:31:24 +00:00
|
|
|
void rowClicked(not_null<PeerListRow*> row) override;
|
2017-06-16 11:05:13 +00:00
|
|
|
void loadMoreRows() override;
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
std::unique_ptr<PeerListRow> createSearchRow(not_null<PeerData*> peer) override;
|
2017-06-16 11:05:13 +00:00
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
// Callback(not_null<UserData*>)
|
2017-06-16 11:05:13 +00:00
|
|
|
template <typename Callback>
|
2017-08-17 08:31:24 +00:00
|
|
|
static void HandleParticipant(const MTPChannelParticipant &participant, not_null<Additional*> additional, Callback callback);
|
2017-06-16 11:05:13 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
template <typename Callback>
|
2017-08-17 08:31:24 +00:00
|
|
|
bool checkInfoLoaded(not_null<UserData*> user, Callback callback);
|
|
|
|
|
|
|
|
void showAdmin(not_null<UserData*> user, bool sure = false);
|
2019-01-03 14:39:19 +00:00
|
|
|
void editAdminDone(not_null<UserData*> user, const MTPChatAdminRights &rights);
|
2017-08-17 08:31:24 +00:00
|
|
|
void showRestricted(not_null<UserData*> user, bool sure = false);
|
2019-01-03 14:39:19 +00:00
|
|
|
void editRestrictedDone(not_null<UserData*> user, const MTPChatBannedRights &rights);
|
2017-08-17 08:31:24 +00:00
|
|
|
void kickUser(not_null<UserData*> user, bool sure = false);
|
2019-01-03 14:39:19 +00:00
|
|
|
void restrictUserSure(not_null<UserData*> user, const MTPChatBannedRights &oldRights, const MTPChatBannedRights &newRights);
|
2017-08-17 08:31:24 +00:00
|
|
|
bool appendRow(not_null<UserData*> user);
|
|
|
|
bool prependRow(not_null<UserData*> user);
|
|
|
|
std::unique_ptr<PeerListRow> createRow(not_null<UserData*> user) const;
|
|
|
|
|
|
|
|
not_null<ChannelData*> _channel;
|
2017-06-16 11:05:13 +00:00
|
|
|
Role _role = Role::Admins;
|
|
|
|
int _offset = 0;
|
|
|
|
mtpRequestId _loadRequestId = 0;
|
|
|
|
bool _allLoaded = false;
|
|
|
|
Additional _additional;
|
|
|
|
QPointer<BoxContent> _editBox;
|
2017-06-16 13:47:44 +00:00
|
|
|
AdminDoneCallback _adminDoneCallback;
|
|
|
|
BannedDoneCallback _bannedDoneCallback;
|
2017-06-16 11:05:13 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
AddParticipantBoxSearchController(not_null<ChannelData*> channel, not_null<Additional*> additional);
|
2017-06-16 11:05:13 +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();
|
|
|
|
void addChatsContacts();
|
|
|
|
void requestGlobal();
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<ChannelData*> _channel;
|
|
|
|
not_null<Additional*> _additional;
|
2017-06-16 11:05:13 +00:00
|
|
|
|
|
|
|
base::Timer _timer;
|
|
|
|
QString _query;
|
|
|
|
mtpRequestId _requestId = 0;
|
|
|
|
int _offset = 0;
|
|
|
|
bool _participantsLoaded = false;
|
|
|
|
bool _chatsContactsAdded = false;
|
|
|
|
bool _globalLoaded = false;
|
|
|
|
std::map<QString, CacheEntry> _participantsCache;
|
|
|
|
std::map<mtpRequestId, Query> _participantsQueries;
|
|
|
|
std::map<QString, MTPcontacts_Found> _globalCache;
|
|
|
|
std::map<mtpRequestId, QString> _globalQueries;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Profile
|