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
|
|
|
|
2016-06-01 16:07:03 +03:00
|
|
|
#include "mainwindow.h" // tmp
|
|
|
|
|
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 00:08:47 +03:00
|
|
|
class BlockedBoxSearchController : public PeerListSearchController, private MTP::Sender {
|
2017-04-07 18:07:26 +03:00
|
|
|
public:
|
2017-06-14 00:08:47 +03:00
|
|
|
BlockedBoxSearchController(gsl::not_null<ChannelData*> channel, bool restricted, gsl::not_null<std::map<UserData*, MTPChannelBannedRights>*> rights);
|
|
|
|
|
|
|
|
void searchQuery(const QString &query) override;
|
|
|
|
bool isLoading() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool searchInCache();
|
|
|
|
void searchOnServer();
|
|
|
|
void searchDone(const MTPchannels_ChannelParticipants &result, mtpRequestId requestId);
|
|
|
|
|
|
|
|
gsl::not_null<ChannelData*> _channel;
|
|
|
|
bool _restricted = false;
|
|
|
|
gsl::not_null<std::map<UserData*, MTPChannelBannedRights>*> _rights;
|
|
|
|
|
|
|
|
base::Timer _timer;
|
|
|
|
QString _query;
|
|
|
|
mtpRequestId _requestId = 0;
|
|
|
|
int _offset = 0;
|
|
|
|
bool _allLoaded = false;
|
|
|
|
std::map<QString, MTPchannels_ChannelParticipants> _cache;
|
|
|
|
std::map<mtpRequestId, QString> _queries;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
BlockedBoxSearchController::BlockedBoxSearchController(gsl::not_null<ChannelData*> channel, bool restricted, gsl::not_null<std::map<UserData*, MTPChannelBannedRights>*> rights)
|
|
|
|
: _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;
|
|
|
|
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());
|
|
|
|
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, _query);
|
|
|
|
}
|
|
|
|
|
|
|
|
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()) {
|
|
|
|
query = it->second;
|
|
|
|
_cache[query] = result;
|
|
|
|
_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 {
|
|
|
|
LOG(("API Error: Non kicked participant got while requesting for kicked participants: %1").arg(participant.type()));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delegate()->peerListSearchRefreshRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BlockedBoxSearchController::isLoading() {
|
|
|
|
return _timer.isActive() || _requestId;
|
|
|
|
}
|
|
|
|
|
|
|
|
class BlockedBoxController : public PeerListController, private base::Subscriber, private MTP::Sender, public base::enable_weak_from_this {
|
|
|
|
public:
|
|
|
|
BlockedBoxController(gsl::not_null<ChannelData*> channel, bool restricted);
|
2017-04-07 18:07:26 +03:00
|
|
|
|
|
|
|
void prepare() override;
|
2017-06-14 00:08:47 +03:00
|
|
|
void rowClicked(gsl::not_null<PeerListRow*> row) override;
|
|
|
|
void rowActionClicked(gsl::not_null<PeerListRow*> row) override;
|
2017-04-07 18:07:26 +03:00
|
|
|
void preloadRows() override;
|
2017-06-14 00:08:47 +03:00
|
|
|
bool searchInLocal() override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void peerListSearchAddRow(gsl::not_null<PeerData*> peer) override;
|
2017-04-07 18:07:26 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool appendRow(UserData *user);
|
|
|
|
bool prependRow(UserData *user);
|
2017-06-14 00:08:47 +03:00
|
|
|
std::unique_ptr<PeerListRow> createRow(UserData *user) const;
|
2017-04-07 18:07:26 +03:00
|
|
|
|
2017-06-14 00:08:47 +03:00
|
|
|
gsl::not_null<ChannelData*> _channel;
|
|
|
|
bool _restricted = false;
|
2017-04-07 18:07:26 +03:00
|
|
|
int _offset = 0;
|
|
|
|
mtpRequestId _loadRequestId = 0;
|
|
|
|
bool _allLoaded = false;
|
2017-06-14 00:08:47 +03:00
|
|
|
std::map<UserData*, MTPChannelBannedRights> _rights;
|
|
|
|
QPointer<EditRestrictedBox> _editBox;
|
2017-04-07 18:07:26 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-06-14 00:08:47 +03:00
|
|
|
void BlockedBoxController::peerListSearchAddRow(gsl::not_null<PeerData*> peer) {
|
|
|
|
PeerListController::peerListSearchAddRow(peer);
|
|
|
|
if (_restricted && delegate()->peerListFullRowsCount() > 0) {
|
|
|
|
setDescriptionText(QString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockedBoxController::BlockedBoxController(gsl::not_null<ChannelData*> channel, bool restricted) : PeerListController(std::make_unique<BlockedBoxSearchController>(channel, restricted, &_rights))
|
|
|
|
, _channel(channel)
|
|
|
|
, _restricted(restricted) {
|
|
|
|
}
|
|
|
|
|
2017-04-07 18:07:26 +03:00
|
|
|
void BlockedBoxController::prepare() {
|
2017-06-14 00:08:47 +03:00
|
|
|
delegate()->peerListSetSearchMode(PeerListSearchMode::Complex);
|
|
|
|
delegate()->peerListSetTitle(langFactory(_restricted ? lng_restricted_list_title : lng_blocked_list_title));
|
|
|
|
setDescriptionText(lang(lng_contacts_loading));
|
|
|
|
setSearchNoResultsText(lang(lng_blocked_list_not_found));
|
|
|
|
delegate()->peerListRefreshRows();
|
2017-04-07 18:07:26 +03:00
|
|
|
|
|
|
|
preloadRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockedBoxController::preloadRows() {
|
|
|
|
if (_loadRequestId || _allLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-14 00:08:47 +03:00
|
|
|
auto filter = _restricted ? MTP_channelParticipantsBanned(MTP_string(QString())) : MTP_channelParticipantsKicked(MTP_string(QString()));
|
|
|
|
_loadRequestId = request(MTPchannels_GetParticipants(_channel->inputChannel, filter, MTP_int(_offset), MTP_int(kBlockedPerPage))).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 00:08:47 +03:00
|
|
|
setDescriptionText(_restricted ? QString() : lang(lng_group_blocked_list_about));
|
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 00:08:47 +03:00
|
|
|
if (participant.type() == mtpc_channelParticipantBanned) {
|
|
|
|
auto &banned = participant.c_channelParticipantBanned();
|
|
|
|
auto userId = banned.vuser_id.v;
|
|
|
|
if (auto user = App::userLoaded(userId)) {
|
|
|
|
appendRow(user);
|
|
|
|
_rights[user] = banned.vbanned_rights;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(("API Error: Non kicked participant got while requesting for kicked 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 00:08:47 +03:00
|
|
|
void BlockedBoxController::rowClicked(gsl::not_null<PeerListRow*> row) {
|
2017-04-07 18:07:26 +03:00
|
|
|
Ui::showPeerHistoryAsync(row->peer()->id, ShowAtUnreadMsgId);
|
|
|
|
}
|
|
|
|
|
2017-06-14 00:08:47 +03:00
|
|
|
void BlockedBoxController::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 00:08:47 +03:00
|
|
|
if (_restricted) {
|
|
|
|
auto it = _rights.find(user);
|
|
|
|
t_assert(it != _rights.cend());
|
|
|
|
auto weak = base::weak_unique_ptr<BlockedBoxController>(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);
|
|
|
|
weak->delegate()->peerListRefreshRows();
|
|
|
|
if (!weak->delegate()->peerListFullRowsCount()) {
|
|
|
|
weak->setDescriptionText(lang(lng_blocked_list_not_found));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
weak->_rights[user] = rights;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}), KeepOtherLayers);
|
|
|
|
} else {
|
|
|
|
delegate()->peerListRemoveRow(row);
|
|
|
|
delegate()->peerListRefreshRows();
|
2017-04-07 18:07:26 +03:00
|
|
|
|
2017-06-14 00:08:47 +03:00
|
|
|
AuthSession::Current().api().unblockParticipant(_channel, user);
|
|
|
|
}
|
2017-04-07 18:07:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BlockedBoxController::appendRow(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));
|
|
|
|
if (_restricted) {
|
|
|
|
setDescriptionText(QString());
|
|
|
|
}
|
2017-04-07 18:07:26 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BlockedBoxController::prependRow(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));
|
|
|
|
if (_restricted) {
|
|
|
|
setDescriptionText(QString());
|
|
|
|
}
|
2017-04-07 18:07:26 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-14 00:08:47 +03:00
|
|
|
std::unique_ptr<PeerListRow> BlockedBoxController::createRow(UserData *user) const {
|
2017-04-27 22:04:45 +03:00
|
|
|
auto row = std::make_unique<PeerListRowWithLink>(user);
|
2017-06-14 00:08:47 +03:00
|
|
|
row->setActionLink(lang(_restricted ? lng_profile_edit_permissions : 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()) {
|
2016-12-13 20:07:56 +03:00
|
|
|
Ui::show(Box<MembersBox>(channel, MembersFilter::Admins));
|
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 00:08:47 +03:00
|
|
|
Ui::show(Box<PeerListBox>(std::make_unique<BlockedBoxController>(channel, false), [](PeerListBox *box) {
|
|
|
|
box->addButton(langFactory(lng_close), [box] { box->closeBox(); });
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::onManageRestrictedUsers() {
|
|
|
|
if (auto channel = peer()->asMegagroup()) {
|
|
|
|
Ui::show(Box<PeerListBox>(std::make_unique<BlockedBoxController>(channel, true), [](PeerListBox *box) {
|
|
|
|
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
|