2016-05-31 22:27:11 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 22:31:31 +04:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-05-31 22:27:11 +03:00
|
|
|
*/
|
2016-10-24 00:03:10 +03:00
|
|
|
#include "profile/profile_block_settings.h"
|
2016-05-31 22:27:11 +03:00
|
|
|
|
|
|
|
#include "styles/style_profile.h"
|
2016-11-16 19:04:25 +03:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-11 16:46:04 +03:00
|
|
|
#include "ui/widgets/checkbox.h"
|
2017-04-06 17:38:10 +03:00
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "boxes/contacts_box.h"
|
2017-04-07 18:07:26 +03:00
|
|
|
#include "boxes/peer_list_box.h"
|
2017-06-14 00:08:47 +03:00
|
|
|
#include "boxes/edit_participant_box.h"
|
2016-06-01 16:07:03 +03:00
|
|
|
#include "observer_peer.h"
|
2017-04-07 18:07:26 +03:00
|
|
|
#include "auth_session.h"
|
2016-06-01 16:07:03 +03:00
|
|
|
#include "mainwidget.h"
|
|
|
|
#include "apiwrap.h"
|
2017-04-13 11:27:10 +03:00
|
|
|
#include "lang/lang_keys.h"
|
2016-05-31 22:27:11 +03:00
|
|
|
|
|
|
|
namespace Profile {
|
2017-04-07 18:07:26 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kBlockedPerPage = 40;
|
2017-06-14 20:13:38 +03:00
|
|
|
constexpr auto kAdminsPerPage = 200;
|
2017-04-07 18:07:26 +03:00
|
|
|
|
2017-06-14 00:08:47 +03:00
|
|
|
class BlockedBoxSearchController : public PeerListSearchController, private MTP::Sender {
|
2017-04-07 18:07:26 +03:00
|
|
|
public:
|
2017-06-14 20:13:38 +03:00
|
|
|
BlockedBoxSearchController(gsl::not_null<ChannelData*> channel, bool restricted, gsl::not_null<std::map<gsl::not_null<UserData*>, MTPChannelBannedRights>*> rights);
|
2017-06-14 00:08:47 +03:00
|
|
|
|
|
|
|
void searchQuery(const QString &query) override;
|
|
|
|
bool isLoading() override;
|
2017-06-14 13:46:06 +03:00
|
|
|
bool loadMoreRows() override;
|
2017-06-14 00:08:47 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool searchInCache();
|
|
|
|
void searchOnServer();
|
|
|
|
void searchDone(const MTPchannels_ChannelParticipants &result, mtpRequestId requestId);
|
|
|
|
|
|
|
|
gsl::not_null<ChannelData*> _channel;
|
|
|
|
bool _restricted = false;
|
2017-06-14 20:13:38 +03:00
|
|
|
gsl::not_null<std::map<gsl::not_null<UserData*>, MTPChannelBannedRights>*> _rights;
|
2017-06-14 00:08:47 +03:00
|
|
|
|
|
|
|
base::Timer _timer;
|
|
|
|
QString _query;
|
|
|
|
mtpRequestId _requestId = 0;
|
|
|
|
int _offset = 0;
|
|
|
|
bool _allLoaded = false;
|
|
|
|
std::map<QString, MTPchannels_ChannelParticipants> _cache;
|
2017-06-14 13:46:06 +03:00
|
|
|
std::map<mtpRequestId, std::pair<QString, int>> _queries; // query, offset
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-06-14 20:13:38 +03:00
|
|
|
class ParticipantsBoxController : public PeerListController, private base::Subscriber, private MTP::Sender, public base::enable_weak_from_this {
|
2017-06-14 13:46:06 +03:00
|
|
|
public:
|
2017-06-14 20:13:38 +03:00
|
|
|
enum class Role {
|
|
|
|
Admins,
|
|
|
|
Restricted,
|
|
|
|
Kicked,
|
|
|
|
};
|
|
|
|
|
|
|
|
ParticipantsBoxController(gsl::not_null<ChannelData*> channel, Role role);
|
2017-06-14 13:46:06 +03:00
|
|
|
|
|
|
|
void prepare() override;
|
|
|
|
void rowClicked(gsl::not_null<PeerListRow*> row) override;
|
|
|
|
void rowActionClicked(gsl::not_null<PeerListRow*> row) override;
|
|
|
|
void loadMoreRows() override;
|
|
|
|
|
|
|
|
void peerListSearchAddRow(gsl::not_null<PeerData*> peer) override;
|
|
|
|
|
|
|
|
private:
|
2017-06-14 20:13:38 +03:00
|
|
|
void editAdmin(gsl::not_null<UserData*> user);
|
|
|
|
void editRestricted(gsl::not_null<UserData*> user);
|
|
|
|
void removeKicked(gsl::not_null<PeerListRow*> row, gsl::not_null<UserData*> user);
|
|
|
|
bool appendRow(gsl::not_null<UserData*> user);
|
|
|
|
bool prependRow(gsl::not_null<UserData*> user);
|
|
|
|
std::unique_ptr<PeerListRow> createRow(gsl::not_null<UserData*> user) const;
|
2017-06-14 13:46:06 +03:00
|
|
|
|
|
|
|
gsl::not_null<ChannelData*> _channel;
|
2017-06-14 20:13:38 +03:00
|
|
|
Role _role = Role::Admins;
|
2017-06-14 13:46:06 +03:00
|
|
|
int _offset = 0;
|
|
|
|
mtpRequestId _loadRequestId = 0;
|
|
|
|
bool _allLoaded = false;
|
2017-06-14 20:13:38 +03:00
|
|
|
std::map<gsl::not_null<UserData*>, MTPChannelAdminRights> _adminRights;
|
|
|
|
std::map<gsl::not_null<UserData*>, bool> _adminCanEdit;
|
|
|
|
std::map<gsl::not_null<UserData*>, gsl::not_null<UserData*>> _adminPromotedBy;
|
|
|
|
std::map<gsl::not_null<UserData*>, MTPChannelBannedRights> _restrictedRights;
|
|
|
|
QPointer<BoxContent> _editBox;
|
2017-06-14 00:08:47 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-06-14 20:13:38 +03:00
|
|
|
BlockedBoxSearchController::BlockedBoxSearchController(gsl::not_null<ChannelData*> channel, bool restricted, gsl::not_null<std::map<gsl::not_null<UserData*>, MTPChannelBannedRights>*> rights)
|
2017-06-14 00:08:47 +03:00
|
|
|
: _channel(channel)
|
|
|
|
, _restricted(restricted)
|
|
|
|
, _rights(rights) {
|
|
|
|
_timer.setCallback([this] { searchOnServer(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockedBoxSearchController::searchQuery(const QString &query) {
|
|
|
|
if (_query != query) {
|
|
|
|
_query = query;
|
|
|
|
_offset = 0;
|
|
|
|
_requestId = 0;
|
2017-06-14 13:46:06 +03:00
|
|
|
_allLoaded = false;
|
2017-06-14 00:08:47 +03:00
|
|
|
if (!_query.isEmpty() && !searchInCache()) {
|
|
|
|
_timer.callOnce(AutoSearchTimeout);
|
|
|
|
} else {
|
|
|
|
_timer.cancel();
|
|
|
|
}
|
2017-04-07 18:07:26 +03:00
|
|
|
}
|
2017-06-14 00:08:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BlockedBoxSearchController::searchInCache() {
|
|
|
|
auto it = _cache.find(_query);
|
|
|
|
if (it != _cache.cend()) {
|
|
|
|
_requestId = 0;
|
|
|
|
searchDone(it->second, _requestId);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockedBoxSearchController::searchOnServer() {
|
|
|
|
Expects(!_query.isEmpty());
|
2017-06-14 13:46:06 +03:00
|
|
|
loadMoreRows();
|
2017-06-14 00:08:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void BlockedBoxSearchController::searchDone(const MTPchannels_ChannelParticipants &result, mtpRequestId requestId) {
|
|
|
|
Expects(result.type() == mtpc_channels_channelParticipants);
|
|
|
|
|
|
|
|
auto &participants = result.c_channels_channelParticipants();
|
|
|
|
auto query = _query;
|
|
|
|
if (requestId) {
|
|
|
|
App::feedUsers(participants.vusers);
|
|
|
|
auto it = _queries.find(requestId);
|
|
|
|
if (it != _queries.cend()) {
|
2017-06-14 13:46:06 +03:00
|
|
|
query = it->second.first; // query
|
|
|
|
if (it->second.second == 0) { // offset
|
|
|
|
_cache[query] = result;
|
|
|
|
}
|
2017-06-14 00:08:47 +03:00
|
|
|
_queries.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_requestId == requestId) {
|
|
|
|
_requestId = 0;
|
|
|
|
auto &list = participants.vparticipants.v;
|
|
|
|
if (list.isEmpty()) {
|
|
|
|
_allLoaded = true;
|
|
|
|
} else {
|
|
|
|
for_const (auto &participant, list) {
|
|
|
|
++_offset;
|
|
|
|
if (participant.type() == mtpc_channelParticipantBanned) {
|
|
|
|
auto &banned = participant.c_channelParticipantBanned();
|
|
|
|
auto userId = banned.vuser_id.v;
|
|
|
|
if (auto user = App::userLoaded(userId)) {
|
|
|
|
delegate()->peerListSearchAddRow(user);
|
|
|
|
(*_rights)[user] = banned.vbanned_rights;
|
|
|
|
}
|
|
|
|
} else {
|
2017-06-14 20:13:38 +03:00
|
|
|
LOG(("API Error: Non banned participant got while requesting for kicked participants: %1").arg(participant.type()));
|
2017-06-14 00:08:47 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delegate()->peerListSearchRefreshRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BlockedBoxSearchController::isLoading() {
|
|
|
|
return _timer.isActive() || _requestId;
|
|
|
|
}
|
|
|
|
|
2017-06-14 13:46:06 +03:00
|
|
|
bool BlockedBoxSearchController::loadMoreRows() {
|
|
|
|
if (_query.isEmpty()) {
|
2017-06-14 00:08:47 +03:00
|
|
|
return false;
|
|
|
|
}
|
2017-06-14 13:46:06 +03:00
|
|
|
if (!_allLoaded && !isLoading()) {
|
|
|
|
auto filter = _restricted ? MTP_channelParticipantsBanned(MTP_string(_query)) : MTP_channelParticipantsKicked(MTP_string(_query));
|
|
|
|
_requestId = request(MTPchannels_GetParticipants(_channel->inputChannel, filter, MTP_int(_offset), MTP_int(kBlockedPerPage))).done([this](const MTPchannels_ChannelParticipants &result, mtpRequestId requestId) {
|
|
|
|
searchDone(result, requestId);
|
|
|
|
}).fail([this](const RPCError &error, mtpRequestId requestId) {
|
|
|
|
if (_requestId == requestId) {
|
|
|
|
_requestId = 0;
|
|
|
|
_allLoaded = true;
|
|
|
|
delegate()->peerListSearchRefreshRows();
|
|
|
|
}
|
|
|
|
}).send();
|
|
|
|
_queries.emplace(_requestId, std::make_pair(_query, _offset));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-07 18:07:26 +03:00
|
|
|
|
2017-06-14 20:13:38 +03:00
|
|
|
ParticipantsBoxController::ParticipantsBoxController(gsl::not_null<ChannelData*> channel, Role role) : PeerListController((role == Role::Admins) ? nullptr : std::make_unique<BlockedBoxSearchController>(channel, (role == Role::Restricted), &_restrictedRights))
|
|
|
|
, _channel(channel)
|
|
|
|
, _role(role) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticipantsBoxController::peerListSearchAddRow(gsl::not_null<PeerData*> peer) {
|
|
|
|
Expects(_role != Role::Admins);
|
2017-06-14 00:08:47 +03:00
|
|
|
PeerListController::peerListSearchAddRow(peer);
|
2017-06-14 20:13:38 +03:00
|
|
|
if (_role == Role::Restricted && delegate()->peerListFullRowsCount() > 0) {
|
2017-06-14 00:08:47 +03:00
|
|
|
setDescriptionText(QString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-14 20:13:38 +03:00
|
|
|
void ParticipantsBoxController::prepare() {
|
|
|
|
if (_role == Role::Admins) {
|
|
|
|
delegate()->peerListSetSearchMode(PeerListSearchMode::Local);
|
|
|
|
delegate()->peerListSetTitle(langFactory(lng_channel_admins));
|
|
|
|
} else {
|
|
|
|
delegate()->peerListSetSearchMode(PeerListSearchMode::Complex);
|
|
|
|
if (_role == Role::Restricted) {
|
|
|
|
delegate()->peerListSetTitle(langFactory(lng_restricted_list_title));
|
|
|
|
} else {
|
|
|
|
delegate()->peerListSetTitle(langFactory(lng_blocked_list_title));
|
|
|
|
}
|
|
|
|
}
|
2017-06-14 00:08:47 +03:00
|
|
|
setDescriptionText(lang(lng_contacts_loading));
|
|
|
|
setSearchNoResultsText(lang(lng_blocked_list_not_found));
|
|
|
|
delegate()->peerListRefreshRows();
|
2017-04-07 18:07:26 +03:00
|
|
|
|
2017-06-14 13:46:06 +03:00
|
|
|
loadMoreRows();
|
2017-04-07 18:07:26 +03:00
|
|
|
}
|
|
|
|
|
2017-06-14 20:13:38 +03:00
|
|
|
void ParticipantsBoxController::loadMoreRows() {
|
|
|
|
if (searchController() && searchController()->loadMoreRows()) {
|
2017-06-14 13:46:06 +03:00
|
|
|
return;
|
|
|
|
}
|
2017-04-07 18:07:26 +03:00
|
|
|
if (_loadRequestId || _allLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-14 20:13:38 +03:00
|
|
|
auto filter = [this] {
|
|
|
|
if (_role == Role::Admins) {
|
|
|
|
return MTP_channelParticipantsAdmins();
|
|
|
|
} else if (_role == Role::Restricted) {
|
|
|
|
return MTP_channelParticipantsBanned(MTP_string(QString()));
|
|
|
|
}
|
|
|
|
return MTP_channelParticipantsKicked(MTP_string(QString()));
|
|
|
|
};
|
|
|
|
auto perPage = (_role == Role::Admins) ? kAdminsPerPage : kBlockedPerPage;
|
|
|
|
_loadRequestId = request(MTPchannels_GetParticipants(_channel->inputChannel, filter(), MTP_int(_offset), MTP_int(perPage))).done([this](const MTPchannels_ChannelParticipants &result) {
|
2017-04-07 18:07:26 +03:00
|
|
|
Expects(result.type() == mtpc_channels_channelParticipants);
|
|
|
|
|
|
|
|
_loadRequestId = 0;
|
|
|
|
|
|
|
|
if (!_offset) {
|
2017-06-14 20:13:38 +03:00
|
|
|
setDescriptionText((_role == Role::Restricted) ? lang(lng_group_blocked_list_about) : QString());
|
2017-04-07 18:07:26 +03:00
|
|
|
}
|
|
|
|
auto &participants = result.c_channels_channelParticipants();
|
|
|
|
App::feedUsers(participants.vusers);
|
|
|
|
|
|
|
|
auto &list = participants.vparticipants.v;
|
|
|
|
if (list.isEmpty()) {
|
|
|
|
_allLoaded = true;
|
|
|
|
} else {
|
|
|
|
for_const (auto &participant, list) {
|
|
|
|
++_offset;
|
2017-06-14 20:13:38 +03:00
|
|
|
if (_role == Role::Admins && participant.type() == mtpc_channelParticipantAdmin) {
|
|
|
|
auto &admin = participant.c_channelParticipantAdmin();
|
|
|
|
if (auto user = App::userLoaded(admin.vuser_id.v)) {
|
|
|
|
_adminRights.emplace(user, admin.vadmin_rights);
|
|
|
|
if (admin.is_can_edit()) {
|
|
|
|
_adminCanEdit.emplace(user, true);
|
|
|
|
} else {
|
|
|
|
_adminCanEdit.erase(user);
|
|
|
|
}
|
|
|
|
if (auto promoted = App::userLoaded(admin.vpromoted_by.v)) {
|
|
|
|
_adminPromotedBy.emplace(user, promoted);
|
|
|
|
} else {
|
|
|
|
LOG(("API Error: No user %1 for admin promoted by.").arg(admin.vpromoted_by.v));
|
|
|
|
}
|
|
|
|
appendRow(user);
|
|
|
|
}
|
|
|
|
} else if (_role == Role::Admins && participant.type() == mtpc_channelParticipantCreator) {
|
|
|
|
auto &creator = participant.c_channelParticipantCreator();
|
|
|
|
if (auto user = App::userLoaded(creator.vuser_id.v)) {
|
|
|
|
_adminCanEdit.erase(user);
|
|
|
|
appendRow(user);
|
|
|
|
}
|
|
|
|
} else if ((_role == Role::Restricted || _role == Role::Kicked) && participant.type() == mtpc_channelParticipantBanned) {
|
2017-06-14 00:08:47 +03:00
|
|
|
auto &banned = participant.c_channelParticipantBanned();
|
2017-06-14 20:13:38 +03:00
|
|
|
if (auto user = App::userLoaded(banned.vuser_id.v)) {
|
|
|
|
_restrictedRights.emplace(user, banned.vbanned_rights);
|
2017-06-14 00:08:47 +03:00
|
|
|
appendRow(user);
|
|
|
|
}
|
|
|
|
} else {
|
2017-06-14 20:13:38 +03:00
|
|
|
LOG(("API Error: Bad participant type got while requesting for participants: %1").arg(participant.type()));
|
2017-04-07 18:07:26 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-14 00:08:47 +03:00
|
|
|
delegate()->peerListRefreshRows();
|
2017-04-07 18:07:26 +03:00
|
|
|
}).fail([this](const RPCError &error) {
|
|
|
|
_loadRequestId = 0;
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
2017-06-14 20:13:38 +03:00
|
|
|
void ParticipantsBoxController::rowClicked(gsl::not_null<PeerListRow*> row) {
|
2017-04-07 18:07:26 +03:00
|
|
|
Ui::showPeerHistoryAsync(row->peer()->id, ShowAtUnreadMsgId);
|
|
|
|
}
|
|
|
|
|
2017-06-14 20:13:38 +03:00
|
|
|
void ParticipantsBoxController::rowActionClicked(gsl::not_null<PeerListRow*> row) {
|
2017-04-07 18:07:26 +03:00
|
|
|
auto user = row->peer()->asUser();
|
|
|
|
Expects(user != nullptr);
|
|
|
|
|
2017-06-14 20:13:38 +03:00
|
|
|
if (_role == Role::Admins) {
|
|
|
|
editAdmin(user);
|
|
|
|
} else if (_role == Role::Restricted) {
|
|
|
|
editRestricted(user);
|
|
|
|
} else {
|
|
|
|
removeKicked(row, user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticipantsBoxController::editAdmin(gsl::not_null<UserData*> user) {
|
|
|
|
if (_adminCanEdit.find(user) == _adminCanEdit.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto it = _adminRights.find(user);
|
|
|
|
t_assert(it != _adminRights.cend());
|
|
|
|
auto weak = base::weak_unique_ptr<ParticipantsBoxController>(this);
|
|
|
|
_editBox = Ui::show(Box<EditAdminBox>(_channel, user, it->second, [megagroup = _channel.get(), user, weak](const MTPChannelAdminRights &rights) {
|
|
|
|
MTP::send(MTPchannels_EditAdmin(megagroup->inputChannel, user->inputUser, rights), rpcDone([megagroup, user, weak, rights](const MTPUpdates &result) {
|
|
|
|
if (App::main()) App::main()->sentUpdatesReceived(result);
|
|
|
|
megagroup->applyEditAdmin(user, rights);
|
|
|
|
if (weak) {
|
|
|
|
weak->_editBox->closeBox();
|
|
|
|
if (rights.c_channelAdminRights().vflags.v == 0) {
|
|
|
|
if (auto row = weak->delegate()->peerListFindRow(user->id)) {
|
|
|
|
weak->delegate()->peerListRemoveRow(row);
|
|
|
|
if (!weak->delegate()->peerListFullRowsCount()) {
|
|
|
|
weak->setDescriptionText(lang(lng_blocked_list_not_found));
|
2017-06-14 00:08:47 +03:00
|
|
|
}
|
2017-06-14 20:13:38 +03:00
|
|
|
weak->delegate()->peerListRefreshRows();
|
2017-06-14 00:08:47 +03:00
|
|
|
}
|
2017-06-14 20:13:38 +03:00
|
|
|
} else {
|
|
|
|
weak->_adminRights[user] = rights;
|
2017-06-14 00:08:47 +03:00
|
|
|
}
|
2017-06-14 20:13:38 +03:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
}), KeepOtherLayers);
|
|
|
|
}
|
2017-04-07 18:07:26 +03:00
|
|
|
|
2017-06-14 20:13:38 +03:00
|
|
|
void ParticipantsBoxController::editRestricted(gsl::not_null<UserData*> user) {
|
|
|
|
auto it = _restrictedRights.find(user);
|
|
|
|
t_assert(it != _restrictedRights.cend());
|
|
|
|
auto weak = base::weak_unique_ptr<ParticipantsBoxController>(this);
|
|
|
|
_editBox = Ui::show(Box<EditRestrictedBox>(_channel, user, it->second, [megagroup = _channel.get(), user, weak](const MTPChannelBannedRights &rights) {
|
|
|
|
MTP::send(MTPchannels_EditBanned(megagroup->inputChannel, user->inputUser, rights), rpcDone([megagroup, user, weak, rights](const MTPUpdates &result) {
|
|
|
|
if (App::main()) App::main()->sentUpdatesReceived(result);
|
|
|
|
megagroup->applyEditBanned(user, rights);
|
|
|
|
if (weak) {
|
|
|
|
weak->_editBox->closeBox();
|
|
|
|
if (rights.c_channelBannedRights().vflags.v == 0 || rights.c_channelBannedRights().is_view_messages()) {
|
|
|
|
if (auto row = weak->delegate()->peerListFindRow(user->id)) {
|
|
|
|
weak->delegate()->peerListRemoveRow(row);
|
|
|
|
if (!weak->delegate()->peerListFullRowsCount()) {
|
|
|
|
weak->setDescriptionText(lang(lng_blocked_list_not_found));
|
|
|
|
}
|
|
|
|
weak->delegate()->peerListRefreshRows();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
weak->_restrictedRights[user] = rights;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}), KeepOtherLayers);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticipantsBoxController::removeKicked(gsl::not_null<PeerListRow*> row, gsl::not_null<UserData*> user) {
|
|
|
|
delegate()->peerListRemoveRow(row);
|
|
|
|
delegate()->peerListRefreshRows();
|
|
|
|
|
|
|
|
AuthSession::Current().api().unblockParticipant(_channel, user);
|
2017-04-07 18:07:26 +03:00
|
|
|
}
|
|
|
|
|
2017-06-14 20:13:38 +03:00
|
|
|
bool ParticipantsBoxController::appendRow(gsl::not_null<UserData*> user) {
|
2017-06-14 00:08:47 +03:00
|
|
|
if (delegate()->peerListFindRow(user->id)) {
|
2017-04-07 18:07:26 +03:00
|
|
|
return false;
|
|
|
|
}
|
2017-06-14 00:08:47 +03:00
|
|
|
delegate()->peerListAppendRow(createRow(user));
|
2017-06-14 20:13:38 +03:00
|
|
|
if (_role != Role::Kicked) {
|
2017-06-14 00:08:47 +03:00
|
|
|
setDescriptionText(QString());
|
|
|
|
}
|
2017-04-07 18:07:26 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-14 20:13:38 +03:00
|
|
|
bool ParticipantsBoxController::prependRow(gsl::not_null<UserData*> user) {
|
2017-06-14 00:08:47 +03:00
|
|
|
if (delegate()->peerListFindRow(user->id)) {
|
2017-04-07 18:07:26 +03:00
|
|
|
return false;
|
|
|
|
}
|
2017-06-14 00:08:47 +03:00
|
|
|
delegate()->peerListPrependRow(createRow(user));
|
2017-06-14 20:13:38 +03:00
|
|
|
if (_role != Role::Kicked) {
|
2017-06-14 00:08:47 +03:00
|
|
|
setDescriptionText(QString());
|
|
|
|
}
|
2017-04-07 18:07:26 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-14 20:13:38 +03:00
|
|
|
std::unique_ptr<PeerListRow> ParticipantsBoxController::createRow(gsl::not_null<UserData*> user) const {
|
2017-04-27 22:04:45 +03:00
|
|
|
auto row = std::make_unique<PeerListRowWithLink>(user);
|
2017-06-14 20:13:38 +03:00
|
|
|
if (_role == Role::Admins) {
|
|
|
|
auto promotedBy = _adminPromotedBy.find(user);
|
|
|
|
if (promotedBy == _adminPromotedBy.end()) {
|
|
|
|
row->setCustomStatus(lang(lng_channel_admin_status_creator));
|
|
|
|
} else {
|
|
|
|
row->setCustomStatus(lng_channel_admin_status_promoted_by(lt_user, App::peerName(promotedBy->second)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_role == Role::Restricted || (_role == Role::Admins && _adminCanEdit.find(user) != _adminCanEdit.end())) {
|
|
|
|
row->setActionLink(lang(lng_profile_edit_permissions));
|
|
|
|
} else if (_role == Role::Kicked) {
|
|
|
|
row->setActionLink(lang(lng_blocked_list_unblock));
|
|
|
|
}
|
2017-04-27 22:04:45 +03:00
|
|
|
return std::move(row);
|
2017-04-07 18:07:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2016-05-31 22:27:11 +03:00
|
|
|
|
2016-06-01 23:05:37 +03:00
|
|
|
using UpdateFlag = Notify::PeerUpdate::Flag;
|
|
|
|
|
2016-05-31 22:27:11 +03:00
|
|
|
SettingsWidget::SettingsWidget(QWidget *parent, PeerData *peer) : BlockWidget(parent, peer, lang(lng_profile_settings_section))
|
2016-06-01 16:07:03 +03:00
|
|
|
, _enableNotifications(this, lang(lng_profile_enable_notifications), true, st::defaultCheckbox) {
|
|
|
|
connect(_enableNotifications, SIGNAL(changed()), this, SLOT(onNotificationsChange()));
|
|
|
|
|
2016-06-01 23:05:37 +03:00
|
|
|
Notify::PeerUpdate::Flags observeEvents = UpdateFlag::NotificationsEnabled;
|
2016-06-01 16:07:03 +03:00
|
|
|
if (auto chat = peer->asChat()) {
|
|
|
|
if (chat->amCreator()) {
|
2016-06-01 23:05:37 +03:00
|
|
|
observeEvents |= UpdateFlag::ChatCanEdit | UpdateFlag::InviteLinkChanged;
|
2016-06-01 16:07:03 +03:00
|
|
|
}
|
|
|
|
} else if (auto channel = peer->asChannel()) {
|
2017-06-09 18:12:02 +02:00
|
|
|
observeEvents |= UpdateFlag::ChannelRightsChanged | UpdateFlag::BlockedUsersChanged | UpdateFlag::UsernameChanged | UpdateFlag::InviteLinkChanged;
|
2016-06-01 16:07:03 +03:00
|
|
|
}
|
2016-09-26 21:33:34 +03:00
|
|
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
2016-09-26 16:57:08 +03:00
|
|
|
notifyPeerUpdated(update);
|
2016-09-26 21:33:34 +03:00
|
|
|
}));
|
2016-06-01 16:07:03 +03:00
|
|
|
|
|
|
|
refreshButtons();
|
|
|
|
_enableNotifications->finishAnimations();
|
|
|
|
|
2016-05-31 22:27:11 +03:00
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
2016-06-01 16:07:03 +03:00
|
|
|
void SettingsWidget::notifyPeerUpdated(const Notify::PeerUpdate &update) {
|
|
|
|
if (update.peer != peer()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-01 23:05:37 +03:00
|
|
|
if (update.flags & UpdateFlag::NotificationsEnabled) {
|
2016-06-01 16:07:03 +03:00
|
|
|
refreshEnableNotifications();
|
|
|
|
}
|
2017-06-09 18:12:02 +02:00
|
|
|
if (update.flags & (UpdateFlag::ChannelRightsChanged | UpdateFlag::ChatCanEdit | UpdateFlag::UsernameChanged | UpdateFlag::InviteLinkChanged)) {
|
2016-06-01 16:07:03 +03:00
|
|
|
refreshInviteLinkButton();
|
|
|
|
}
|
2017-06-09 18:12:02 +02:00
|
|
|
if (update.flags & (UpdateFlag::ChannelRightsChanged | UpdateFlag::ChatCanEdit)) {
|
2016-06-01 16:07:03 +03:00
|
|
|
refreshManageAdminsButton();
|
|
|
|
}
|
2017-06-09 18:12:02 +02:00
|
|
|
if (update.flags & (UpdateFlag::ChannelRightsChanged | UpdateFlag::BlockedUsersChanged)) {
|
2017-04-07 18:07:26 +03:00
|
|
|
refreshManageBlockedUsersButton();
|
|
|
|
}
|
2016-06-01 16:07:03 +03:00
|
|
|
|
|
|
|
contentSizeUpdated();
|
|
|
|
}
|
|
|
|
|
2016-05-31 22:27:11 +03:00
|
|
|
int SettingsWidget::resizeGetHeight(int newWidth) {
|
2016-06-10 14:18:55 +03:00
|
|
|
int newHeight = contentTop() + st::profileEnableNotificationsTop;
|
2016-05-31 22:27:11 +03:00
|
|
|
|
2016-06-02 16:02:55 +03:00
|
|
|
_enableNotifications->moveToLeft(st::profileBlockTitlePosition.x(), newHeight);
|
2016-12-02 22:16:35 +03:00
|
|
|
newHeight += _enableNotifications->heightNoMargins() + st::profileSettingsBlockSkip;
|
2016-06-01 16:07:03 +03:00
|
|
|
|
2016-06-02 16:02:55 +03:00
|
|
|
auto moveLink = [&newHeight, newWidth](Ui::LeftOutlineButton *button) {
|
2016-06-01 16:07:03 +03:00
|
|
|
if (!button) return;
|
|
|
|
|
2016-06-02 16:02:55 +03:00
|
|
|
int left = defaultOutlineButtonLeft();
|
|
|
|
int availableWidth = newWidth - left - st::profileBlockMarginRight;
|
2016-06-01 16:07:03 +03:00
|
|
|
accumulate_min(availableWidth, st::profileBlockOneLineWidthMax);
|
|
|
|
button->resizeToWidth(availableWidth);
|
2016-06-02 16:02:55 +03:00
|
|
|
button->moveToLeft(left, newHeight);
|
2016-06-01 16:07:03 +03:00
|
|
|
newHeight += button->height();
|
|
|
|
};
|
|
|
|
moveLink(_manageAdmins);
|
2017-04-07 18:07:26 +03:00
|
|
|
moveLink(_manageBlockedUsers);
|
2017-06-14 00:08:47 +03:00
|
|
|
moveLink(_manageRestrictedUsers);
|
2016-06-01 16:07:03 +03:00
|
|
|
moveLink(_inviteLink);
|
|
|
|
|
|
|
|
newHeight += st::profileBlockMarginBottom;
|
2016-05-31 22:27:11 +03:00
|
|
|
return newHeight;
|
|
|
|
}
|
|
|
|
|
2016-06-01 16:07:03 +03:00
|
|
|
void SettingsWidget::refreshButtons() {
|
|
|
|
refreshEnableNotifications();
|
|
|
|
refreshManageAdminsButton();
|
2017-04-07 18:07:26 +03:00
|
|
|
refreshManageBlockedUsersButton();
|
2016-06-01 16:07:03 +03:00
|
|
|
refreshInviteLinkButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::refreshEnableNotifications() {
|
|
|
|
if (peer()->notify == UnknownNotifySettings) {
|
|
|
|
App::api()->requestNotifySetting(peer());
|
|
|
|
} else {
|
|
|
|
auto ¬ifySettings = peer()->notify;
|
|
|
|
bool enabled = (notifySettings == EmptyNotifySettings || notifySettings->mute < unixtime());
|
2016-10-28 12:20:24 +03:00
|
|
|
_enableNotifications->setChecked(enabled, Ui::Checkbox::NotifyAboutChange::DontNotify);
|
2016-06-01 16:07:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::refreshManageAdminsButton() {
|
2017-04-07 18:07:26 +03:00
|
|
|
auto hasManageAdmins = [this] {
|
2016-06-01 16:07:03 +03:00
|
|
|
if (auto chat = peer()->asChat()) {
|
|
|
|
return (chat->amCreator() && chat->canEdit());
|
2017-04-07 18:07:26 +03:00
|
|
|
} else if (auto channel = peer()->asMegagroup()) {
|
2017-06-09 18:12:02 +02:00
|
|
|
return channel->hasAdminRights() || channel->amCreator();
|
2016-06-01 16:07:03 +03:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
_manageAdmins.destroy();
|
|
|
|
if (hasManageAdmins()) {
|
2016-11-15 14:56:49 +03:00
|
|
|
_manageAdmins.create(this, lang(lng_profile_manage_admins), st::defaultLeftOutlineButton);
|
2016-06-01 16:07:03 +03:00
|
|
|
_manageAdmins->show();
|
|
|
|
connect(_manageAdmins, SIGNAL(clicked()), this, SLOT(onManageAdmins()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-07 18:07:26 +03:00
|
|
|
void SettingsWidget::refreshManageBlockedUsersButton() {
|
|
|
|
auto hasManageBlockedUsers = [this] {
|
|
|
|
if (auto channel = peer()->asMegagroup()) {
|
2017-06-14 00:08:47 +03:00
|
|
|
return channel->canBanMembers() && (channel->kickedCount() > 0);
|
2017-04-07 18:07:26 +03:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
_manageBlockedUsers.destroy();
|
|
|
|
if (hasManageBlockedUsers()) {
|
|
|
|
_manageBlockedUsers.create(this, lang(lng_profile_manage_blocklist), st::defaultLeftOutlineButton);
|
|
|
|
_manageBlockedUsers->show();
|
|
|
|
connect(_manageBlockedUsers, SIGNAL(clicked()), this, SLOT(onManageBlockedUsers()));
|
|
|
|
}
|
2017-06-14 00:08:47 +03:00
|
|
|
|
|
|
|
auto hasManageRestrictedUsers = [this] {
|
|
|
|
if (auto channel = peer()->asMegagroup()) {
|
|
|
|
return channel->canBanMembers() && (channel->restrictedCount() > 0);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
_manageRestrictedUsers.destroy();
|
|
|
|
if (hasManageRestrictedUsers()) {
|
|
|
|
_manageRestrictedUsers.create(this, lang(lng_profile_manage_restrictedlist), st::defaultLeftOutlineButton);
|
|
|
|
_manageRestrictedUsers->show();
|
|
|
|
connect(_manageRestrictedUsers, SIGNAL(clicked()), this, SLOT(onManageRestrictedUsers()));
|
|
|
|
}
|
2017-04-07 18:07:26 +03:00
|
|
|
}
|
|
|
|
|
2016-06-01 16:07:03 +03:00
|
|
|
void SettingsWidget::refreshInviteLinkButton() {
|
|
|
|
auto getInviteLinkText = [this]() -> QString {
|
|
|
|
if (auto chat = peer()->asChat()) {
|
|
|
|
if (chat->amCreator() && chat->canEdit()) {
|
|
|
|
return lang(chat->inviteLink().isEmpty() ? lng_group_invite_create : lng_group_invite_create_new);
|
|
|
|
}
|
|
|
|
} else if (auto channel = peer()->asChannel()) {
|
2017-06-09 18:12:02 +02:00
|
|
|
if (channel->canHaveInviteLink() && !channel->isPublic()) {
|
2016-06-01 16:07:03 +03:00
|
|
|
return lang(channel->inviteLink().isEmpty() ? lng_group_invite_create : lng_group_invite_create_new);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
};
|
|
|
|
auto inviteLinkText = getInviteLinkText();
|
2016-06-14 19:26:41 +03:00
|
|
|
if (inviteLinkText.isEmpty()) {
|
|
|
|
_inviteLink.destroy();
|
|
|
|
} else {
|
2016-11-15 14:56:49 +03:00
|
|
|
_inviteLink.create(this, inviteLinkText, st::defaultLeftOutlineButton);
|
2016-06-01 16:07:03 +03:00
|
|
|
_inviteLink->show();
|
|
|
|
connect(_inviteLink, SIGNAL(clicked()), this, SLOT(onInviteLink()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::onNotificationsChange() {
|
|
|
|
App::main()->updateNotifySetting(peer(), _enableNotifications->checked() ? NotifySettingSetNotify : NotifySettingSetMuted);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::onManageAdmins() {
|
|
|
|
if (auto chat = peer()->asChat()) {
|
2016-12-13 20:07:56 +03:00
|
|
|
Ui::show(Box<ContactsBox>(chat, MembersFilter::Admins));
|
2016-06-01 16:07:03 +03:00
|
|
|
} else if (auto channel = peer()->asChannel()) {
|
2017-06-14 20:13:38 +03:00
|
|
|
Ui::show(Box<PeerListBox>(std::make_unique<ParticipantsBoxController>(channel, ParticipantsBoxController::Role::Admins), [](PeerListBox *box) {
|
|
|
|
box->addButton(langFactory(lng_close), [box] { box->closeBox(); });
|
|
|
|
}));
|
2016-06-01 16:07:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-07 18:07:26 +03:00
|
|
|
void SettingsWidget::onManageBlockedUsers() {
|
|
|
|
if (auto channel = peer()->asMegagroup()) {
|
2017-06-14 20:13:38 +03:00
|
|
|
Ui::show(Box<PeerListBox>(std::make_unique<ParticipantsBoxController>(channel, ParticipantsBoxController::Role::Kicked), [](PeerListBox *box) {
|
2017-06-14 00:08:47 +03:00
|
|
|
box->addButton(langFactory(lng_close), [box] { box->closeBox(); });
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::onManageRestrictedUsers() {
|
|
|
|
if (auto channel = peer()->asMegagroup()) {
|
2017-06-14 20:13:38 +03:00
|
|
|
Ui::show(Box<PeerListBox>(std::make_unique<ParticipantsBoxController>(channel, ParticipantsBoxController::Role::Restricted), [](PeerListBox *box) {
|
2017-06-14 00:08:47 +03:00
|
|
|
box->addButton(langFactory(lng_close), [box] { box->closeBox(); });
|
|
|
|
}));
|
2017-04-07 18:07:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-01 16:07:03 +03:00
|
|
|
void SettingsWidget::onInviteLink() {
|
|
|
|
auto getInviteLink = [this]() {
|
|
|
|
if (auto chat = peer()->asChat()) {
|
|
|
|
return chat->inviteLink();
|
|
|
|
} else if (auto channel = peer()->asChannel()) {
|
|
|
|
return channel->inviteLink();
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
};
|
|
|
|
auto link = getInviteLink();
|
|
|
|
|
2016-12-13 20:07:56 +03:00
|
|
|
auto text = lang(link.isEmpty() ? lng_group_invite_about : lng_group_invite_about_new);
|
|
|
|
Ui::show(Box<ConfirmBox>(text, base::lambda_guarded(this, [this] {
|
|
|
|
Ui::hideLayer();
|
|
|
|
App::api()->exportInviteLink(peer());
|
|
|
|
})));
|
2016-06-01 16:07:03 +03:00
|
|
|
}
|
|
|
|
|
2016-05-31 22:27:11 +03:00
|
|
|
} // namespace Profile
|