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 {
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionNavigation;
|
2017-10-03 13:05:58 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(
|
2019-01-03 14:39:19 +00:00
|
|
|
const MTPChatAdminRights &oldRights,
|
2019-07-19 13:34:09 +00:00
|
|
|
const MTPChatAdminRights &newRights,
|
|
|
|
const QString &rank)> SaveAdminCallback(
|
2019-01-10 12:38:57 +00:00
|
|
|
not_null<PeerData*> peer,
|
2018-05-18 14:16:14 +00:00
|
|
|
not_null<UserData*> user,
|
2019-07-19 13:34:09 +00:00
|
|
|
Fn<void(
|
|
|
|
const MTPChatAdminRights &newRights,
|
|
|
|
const QString &rank)> onDone,
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> onFail);
|
2018-05-18 14:16:14 +00:00
|
|
|
|
2019-01-10 06:26:08 +00:00
|
|
|
Fn<void(
|
|
|
|
const MTPChatBannedRights &oldRights,
|
|
|
|
const MTPChatBannedRights &newRights)> SaveRestrictedCallback(
|
2019-01-10 12:38:57 +00:00
|
|
|
not_null<PeerData*> peer,
|
2019-01-10 06:26:08 +00:00
|
|
|
not_null<UserData*> user,
|
|
|
|
Fn<void(const MTPChatBannedRights &newRights)> onDone,
|
|
|
|
Fn<void()> onFail);
|
|
|
|
|
2019-01-13 13:28:05 +00:00
|
|
|
void SubscribeToMigration(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
rpl::lifetime &lifetime,
|
|
|
|
Fn<void(not_null<ChannelData*>)> migrate);
|
|
|
|
|
2019-01-10 11:01:59 +00:00
|
|
|
enum class ParticipantsRole {
|
|
|
|
Profile,
|
|
|
|
Members,
|
|
|
|
Admins,
|
|
|
|
Restricted,
|
|
|
|
Kicked,
|
|
|
|
};
|
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
class ParticipantsOnlineSorter {
|
2019-01-10 06:26:08 +00:00
|
|
|
public:
|
|
|
|
ParticipantsOnlineSorter(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
not_null<PeerListDelegate*> delegate);
|
|
|
|
|
|
|
|
void sort();
|
|
|
|
rpl::producer<int> onlineCountValue() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void sortDelayed();
|
|
|
|
void refreshOnlineCount();
|
|
|
|
|
2020-06-12 12:12:34 +00:00
|
|
|
const not_null<PeerData*> _peer;
|
|
|
|
const not_null<PeerListDelegate*> _delegate;
|
2019-01-10 06:26:08 +00:00
|
|
|
base::Timer _sortByOnlineTimer;
|
|
|
|
rpl::variable<int> _onlineCount = 0;
|
2020-06-12 12:12:34 +00:00
|
|
|
rpl::lifetime _lifetime;
|
2019-01-10 06:26:08 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-01-10 11:01:59 +00:00
|
|
|
class ParticipantsAdditionalData {
|
|
|
|
public:
|
|
|
|
using Role = ParticipantsRole;
|
|
|
|
|
|
|
|
ParticipantsAdditionalData(not_null<PeerData*> peer, Role role);
|
|
|
|
|
|
|
|
UserData *applyParticipant(const MTPChannelParticipant &data);
|
|
|
|
UserData *applyParticipant(
|
|
|
|
const MTPChannelParticipant &data,
|
|
|
|
Role overrideRole);
|
|
|
|
void setExternal(not_null<UserData*> user);
|
|
|
|
void checkForLoaded(not_null<UserData*> user);
|
|
|
|
void fillFromPeer();
|
|
|
|
|
|
|
|
[[nodiscard]] bool infoLoaded(not_null<UserData*> user) const;
|
|
|
|
[[nodiscard]] bool canEditAdmin(not_null<UserData*> user) const;
|
|
|
|
[[nodiscard]] bool canAddOrEditAdmin(not_null<UserData*> user) const;
|
|
|
|
[[nodiscard]] bool canRestrictUser(not_null<UserData*> user) const;
|
2020-06-03 08:57:36 +00:00
|
|
|
[[nodiscard]] bool canRemoveUser(not_null<UserData*> user) const;
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] std::optional<MTPChatAdminRights> adminRights(
|
|
|
|
not_null<UserData*> user) const;
|
2019-07-19 13:34:09 +00:00
|
|
|
QString adminRank(not_null<UserData*> user) const;
|
2019-01-10 11:01:59 +00:00
|
|
|
[[nodiscard]] std::optional<MTPChatBannedRights> restrictedRights(
|
|
|
|
not_null<UserData*> user) const;
|
|
|
|
[[nodiscard]] bool isCreator(not_null<UserData*> user) const;
|
|
|
|
[[nodiscard]] bool isExternal(not_null<UserData*> user) const;
|
|
|
|
[[nodiscard]] bool isKicked(not_null<UserData*> user) const;
|
|
|
|
[[nodiscard]] UserData *adminPromotedBy(not_null<UserData*> user) const;
|
|
|
|
[[nodiscard]] UserData *restrictedBy(not_null<UserData*> user) const;
|
|
|
|
|
2019-01-13 13:28:05 +00:00
|
|
|
void migrate(not_null<ChannelData*> channel);
|
|
|
|
|
2019-01-10 11:01:59 +00:00
|
|
|
private:
|
|
|
|
UserData *applyCreator(const MTPDchannelParticipantCreator &data);
|
|
|
|
UserData *applyAdmin(const MTPDchannelParticipantAdmin &data);
|
|
|
|
UserData *applyRegular(MTPint userId);
|
|
|
|
UserData *applyBanned(const MTPDchannelParticipantBanned &data);
|
|
|
|
void fillFromChat(not_null<ChatData*> chat);
|
|
|
|
void fillFromChannel(not_null<ChannelData*> channel);
|
|
|
|
|
|
|
|
not_null<PeerData*> _peer;
|
|
|
|
Role _role = Role::Members;
|
|
|
|
UserData *_creator = nullptr;
|
|
|
|
|
|
|
|
// Data for chats.
|
|
|
|
base::flat_set<not_null<UserData*>> _members;
|
|
|
|
base::flat_set<not_null<UserData*>> _admins;
|
|
|
|
|
|
|
|
// Data for channels.
|
|
|
|
base::flat_map<not_null<UserData*>, MTPChatAdminRights> _adminRights;
|
2019-07-19 13:34:09 +00:00
|
|
|
base::flat_map<not_null<UserData*>, QString> _adminRanks;
|
2019-01-10 11:01:59 +00:00
|
|
|
base::flat_set<not_null<UserData*>> _adminCanEdit;
|
|
|
|
base::flat_map<not_null<UserData*>, not_null<UserData*>> _adminPromotedBy;
|
|
|
|
std::map<not_null<UserData*>, MTPChatBannedRights> _restrictedRights;
|
|
|
|
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
|
|
|
// Viewing admins, banned or restricted users list with search.
|
2017-09-26 17:57:01 +00:00
|
|
|
class ParticipantsBoxController
|
|
|
|
: public PeerListController
|
2017-11-30 17:33:27 +00:00
|
|
|
, public base::has_weak_ptr {
|
2017-06-16 11:05:13 +00:00
|
|
|
public:
|
2019-01-10 11:01:59 +00:00
|
|
|
using Role = ParticipantsRole;
|
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
static void Start(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
2019-01-10 06:26:08 +00:00
|
|
|
not_null<PeerData*> peer,
|
2017-10-03 13:05:58 +00:00
|
|
|
Role role);
|
2017-06-16 11:05:13 +00:00
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
ParticipantsBoxController(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionNavigation*> navigation,
|
2019-01-10 06:26:08 +00:00
|
|
|
not_null<PeerData*> peer,
|
2017-10-03 13:05:58 +00:00
|
|
|
Role role);
|
2017-06-16 11:05:13 +00:00
|
|
|
|
2019-07-25 18:55:11 +00:00
|
|
|
Main::Session &session() const override;
|
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;
|
|
|
|
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-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:
|
2020-11-28 18:17:13 +00:00
|
|
|
// Allow child controllers not providing navigation.
|
|
|
|
// This is their responsibility to override all methods that use it.
|
|
|
|
struct CreateTag {
|
|
|
|
};
|
|
|
|
ParticipantsBoxController(
|
|
|
|
CreateTag,
|
|
|
|
Window::SessionNavigation *navigation,
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
Role role);
|
|
|
|
|
2019-01-10 06:26:08 +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 {
|
2019-01-10 11:01:59 +00:00
|
|
|
explicit SavedState(const ParticipantsAdditionalData &additional);
|
|
|
|
|
2019-01-10 06:26:08 +00:00
|
|
|
using SearchStateBase = PeerListSearchController::SavedStateBase;
|
|
|
|
std::unique_ptr<SearchStateBase> searchState;
|
2017-10-24 17:11:35 +00:00
|
|
|
int offset = 0;
|
|
|
|
bool allLoaded = false;
|
|
|
|
bool wasLoading = false;
|
2019-01-10 11:01:59 +00:00
|
|
|
ParticipantsAdditionalData additional;
|
2017-10-24 17:11:35 +00:00
|
|
|
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(
|
2019-01-10 06:26:08 +00:00
|
|
|
not_null<PeerData*> peer,
|
2017-10-24 17:11:35 +00:00
|
|
|
Role role,
|
2019-01-10 11:01:59 +00:00
|
|
|
not_null<ParticipantsAdditionalData*> additional);
|
2017-08-17 08:31:24 +00:00
|
|
|
|
2019-01-10 06:26:08 +00:00
|
|
|
void prepareChatRows(not_null<ChatData*> chat);
|
|
|
|
void rebuildChatRows(not_null<ChatData*> chat);
|
2019-01-10 11:01:59 +00:00
|
|
|
void rebuildChatParticipants(not_null<ChatData*> chat);
|
|
|
|
void rebuildChatAdmins(not_null<ChatData*> chat);
|
2019-01-10 12:38:57 +00:00
|
|
|
void chatListReady();
|
2019-01-10 06:26:08 +00:00
|
|
|
void rebuildRowTypes();
|
|
|
|
|
|
|
|
void addNewItem();
|
|
|
|
void addNewParticipants();
|
|
|
|
|
2019-01-15 07:15:38 +00:00
|
|
|
void refreshDescription();
|
2017-10-22 17:06:57 +00:00
|
|
|
void setupListChangeViewers();
|
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-07-19 13:34:09 +00:00
|
|
|
const MTPChatAdminRights &rights,
|
|
|
|
const QString &rank);
|
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);
|
2019-01-21 06:26:19 +00:00
|
|
|
void removeKickedWithRow(not_null<UserData*> user);
|
|
|
|
void removeKicked(not_null<UserData*> user);
|
2017-08-17 08:31:24 +00:00
|
|
|
void kickMember(not_null<UserData*> user);
|
|
|
|
void kickMemberSure(not_null<UserData*> user);
|
2019-01-21 06:26:19 +00:00
|
|
|
void unkickMember(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-11-07 17:53:00 +00:00
|
|
|
Type computeType(not_null<UserData*> user) const;
|
|
|
|
void recomputeTypeFor(not_null<UserData*> user);
|
2017-06-16 11:05:13 +00:00
|
|
|
|
2019-01-13 13:28:05 +00:00
|
|
|
void subscribeToMigration();
|
|
|
|
void migrate(not_null<ChannelData*> channel);
|
2019-06-14 16:04:45 +00:00
|
|
|
void subscribeToCreatorChange(not_null<ChannelData*> channel);
|
|
|
|
void fullListRefresh();
|
2019-01-13 13:28:05 +00:00
|
|
|
|
2020-11-28 18:17:13 +00:00
|
|
|
// It may be nullptr in subclasses of this controller.
|
|
|
|
Window::SessionNavigation *_navigation = nullptr;
|
|
|
|
|
2019-01-10 06:26:08 +00:00
|
|
|
not_null<PeerData*> _peer;
|
2019-11-27 08:02:56 +00:00
|
|
|
MTP::Sender _api;
|
2017-06-16 11:05:13 +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;
|
|
|
|
Ui::BoxPointer _addBox;
|
|
|
|
QPointer<Ui::BoxContent> _editParticipantBox;
|
2017-06-16 11:05:13 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-07-10 16:13:40 +00:00
|
|
|
// Members, banned and restricted users server side search.
|
2019-11-27 08:02:56 +00:00
|
|
|
class ParticipantsBoxSearchController : public PeerListSearchController {
|
2017-06-16 11:05:13 +00:00
|
|
|
public:
|
|
|
|
using Role = ParticipantsBoxController::Role;
|
|
|
|
|
2019-01-10 06:26:08 +00:00
|
|
|
ParticipantsBoxSearchController(
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
Role role,
|
2019-01-10 11:01:59 +00:00
|
|
|
not_null<ParticipantsAdditionalData*> 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;
|
2019-01-10 11:01:59 +00:00
|
|
|
not_null<ParticipantsAdditionalData*> _additional;
|
2019-11-27 08:02:56 +00:00
|
|
|
MTP::Sender _api;
|
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;
|
|
|
|
|
|
|
|
};
|