2016-05-31 19:27:11 +00: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 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-05-31 19:27:11 +00:00
|
|
|
*/
|
2016-10-23 21:03:10 +00:00
|
|
|
#include "profile/profile_block_settings.h"
|
2016-05-31 19:27:11 +00:00
|
|
|
|
|
|
|
#include "styles/style_profile.h"
|
2016-11-16 16:04:25 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "boxes/contacts_box.h"
|
2017-04-07 15:07:26 +00:00
|
|
|
#include "boxes/peer_list_box.h"
|
2016-06-01 13:07:03 +00:00
|
|
|
#include "observer_peer.h"
|
2017-04-07 15:07:26 +00:00
|
|
|
#include "auth_session.h"
|
2016-06-01 13:07:03 +00:00
|
|
|
#include "mainwidget.h"
|
|
|
|
#include "apiwrap.h"
|
2016-05-31 19:27:11 +00:00
|
|
|
#include "lang.h"
|
|
|
|
|
2016-06-01 13:07:03 +00:00
|
|
|
#include "mainwindow.h" // tmp
|
|
|
|
|
2016-05-31 19:27:11 +00:00
|
|
|
namespace Profile {
|
2017-04-07 15:07:26 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kBlockedPerPage = 40;
|
|
|
|
|
|
|
|
class BlockedBoxController : public PeerListBox::Controller, private base::Subscriber, private MTP::Sender {
|
|
|
|
public:
|
|
|
|
BlockedBoxController(ChannelData *channel) : _channel(channel) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void prepare() override;
|
|
|
|
void rowClicked(PeerListBox::Row *row) override;
|
|
|
|
void rowActionClicked(PeerListBox::Row *row) override;
|
|
|
|
void preloadRows() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool appendRow(UserData *user);
|
|
|
|
bool prependRow(UserData *user);
|
|
|
|
std::unique_ptr<PeerListBox::Row> createRow(UserData *user) const;
|
|
|
|
|
|
|
|
ChannelData *_channel = nullptr;
|
|
|
|
int _offset = 0;
|
|
|
|
mtpRequestId _loadRequestId = 0;
|
|
|
|
bool _allLoaded = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
void BlockedBoxController::prepare() {
|
|
|
|
view()->setTitle(lang(lng_blocked_list_title));
|
|
|
|
view()->addButton(lang(lng_close), [this] { view()->closeBox(); });
|
|
|
|
view()->setAboutText(lang(lng_contacts_loading));
|
|
|
|
view()->refreshRows();
|
|
|
|
|
|
|
|
preloadRows();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockedBoxController::preloadRows() {
|
|
|
|
if (_loadRequestId || _allLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_loadRequestId = request(MTPchannels_GetParticipants(_channel->inputChannel, MTP_channelParticipantsKicked(), MTP_int(_offset), MTP_int(kBlockedPerPage))).done([this](const MTPchannels_ChannelParticipants &result) {
|
|
|
|
Expects(result.type() == mtpc_channels_channelParticipants);
|
|
|
|
|
|
|
|
_loadRequestId = 0;
|
|
|
|
|
|
|
|
if (!_offset) {
|
|
|
|
view()->setAboutText(lang(lng_group_blocked_list_about));
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
if (participant.type() != mtpc_channelParticipantKicked) {
|
|
|
|
LOG(("API Error: Non kicked participant got while requesting for kicked participants: %1").arg(participant.type()));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
auto &kicked = participant.c_channelParticipantKicked();
|
|
|
|
auto userId = kicked.vuser_id.v;
|
|
|
|
if (auto user = App::userLoaded(userId)) {
|
|
|
|
appendRow(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
view()->refreshRows();
|
|
|
|
}).fail([this](const RPCError &error) {
|
|
|
|
_loadRequestId = 0;
|
|
|
|
}).send();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockedBoxController::rowClicked(PeerListBox::Row *row) {
|
|
|
|
Ui::showPeerHistoryAsync(row->peer()->id, ShowAtUnreadMsgId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockedBoxController::rowActionClicked(PeerListBox::Row *row) {
|
|
|
|
auto user = row->peer()->asUser();
|
|
|
|
Expects(user != nullptr);
|
|
|
|
|
|
|
|
view()->removeRow(row);
|
|
|
|
view()->refreshRows();
|
|
|
|
|
|
|
|
AuthSession::Current().api().unblockParticipant(_channel, user);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BlockedBoxController::appendRow(UserData *user) {
|
2017-04-27 19:04:45 +00:00
|
|
|
if (view()->findRow(user->id)) {
|
2017-04-07 15:07:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
view()->appendRow(createRow(user));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BlockedBoxController::prependRow(UserData *user) {
|
2017-04-27 19:04:45 +00:00
|
|
|
if (view()->findRow(user->id)) {
|
2017-04-07 15:07:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
view()->prependRow(createRow(user));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<PeerListBox::Row> BlockedBoxController::createRow(UserData *user) const {
|
2017-04-27 19:04:45 +00:00
|
|
|
auto row = std::make_unique<PeerListRowWithLink>(user);
|
2017-04-07 15:07:26 +00:00
|
|
|
row->setActionLink(lang(lng_blocked_list_unblock));
|
|
|
|
auto status = [user]() -> QString {
|
|
|
|
if (user->botInfo) {
|
|
|
|
return lang(lng_status_bot);
|
|
|
|
} else if (user->phone().isEmpty()) {
|
|
|
|
return lang(lng_blocked_list_unknown_phone);
|
|
|
|
}
|
|
|
|
return App::formatPhone(user->phone());
|
|
|
|
};
|
|
|
|
row->setCustomStatus(status());
|
2017-04-27 19:04:45 +00:00
|
|
|
return std::move(row);
|
2017-04-07 15:07:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2016-05-31 19:27:11 +00:00
|
|
|
|
2016-06-01 20:05:37 +00:00
|
|
|
using UpdateFlag = Notify::PeerUpdate::Flag;
|
|
|
|
|
2016-05-31 19:27:11 +00:00
|
|
|
SettingsWidget::SettingsWidget(QWidget *parent, PeerData *peer) : BlockWidget(parent, peer, lang(lng_profile_settings_section))
|
2016-06-01 13:07:03 +00:00
|
|
|
, _enableNotifications(this, lang(lng_profile_enable_notifications), true, st::defaultCheckbox) {
|
|
|
|
connect(_enableNotifications, SIGNAL(changed()), this, SLOT(onNotificationsChange()));
|
|
|
|
|
2016-06-01 20:05:37 +00:00
|
|
|
Notify::PeerUpdate::Flags observeEvents = UpdateFlag::NotificationsEnabled;
|
2016-06-01 13:07:03 +00:00
|
|
|
if (auto chat = peer->asChat()) {
|
|
|
|
if (chat->amCreator()) {
|
2016-06-01 20:05:37 +00:00
|
|
|
observeEvents |= UpdateFlag::ChatCanEdit | UpdateFlag::InviteLinkChanged;
|
2016-06-01 13:07:03 +00:00
|
|
|
}
|
|
|
|
} else if (auto channel = peer->asChannel()) {
|
|
|
|
if (channel->amCreator()) {
|
2016-06-01 20:05:37 +00:00
|
|
|
observeEvents |= UpdateFlag::UsernameChanged | UpdateFlag::InviteLinkChanged;
|
2016-06-01 13:07:03 +00:00
|
|
|
}
|
2017-04-07 15:07:26 +00:00
|
|
|
observeEvents |= UpdateFlag::ChannelAmEditor | UpdateFlag::BlockedUsersChanged;
|
2016-06-01 13:07:03 +00:00
|
|
|
}
|
2016-09-26 18:33:34 +00:00
|
|
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
2016-09-26 13:57:08 +00:00
|
|
|
notifyPeerUpdated(update);
|
2016-09-26 18:33:34 +00:00
|
|
|
}));
|
2016-06-01 13:07:03 +00:00
|
|
|
|
|
|
|
refreshButtons();
|
|
|
|
_enableNotifications->finishAnimations();
|
|
|
|
|
2016-05-31 19:27:11 +00:00
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
2016-06-01 13:07:03 +00:00
|
|
|
void SettingsWidget::notifyPeerUpdated(const Notify::PeerUpdate &update) {
|
|
|
|
if (update.peer != peer()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-01 20:05:37 +00:00
|
|
|
if (update.flags & UpdateFlag::NotificationsEnabled) {
|
2016-06-01 13:07:03 +00:00
|
|
|
refreshEnableNotifications();
|
|
|
|
}
|
2016-06-01 20:05:37 +00:00
|
|
|
if (update.flags & (UpdateFlag::ChatCanEdit | UpdateFlag::UsernameChanged | UpdateFlag::InviteLinkChanged)) {
|
2016-06-01 13:07:03 +00:00
|
|
|
refreshInviteLinkButton();
|
|
|
|
}
|
2016-06-01 20:05:37 +00:00
|
|
|
if (update.flags & (UpdateFlag::ChatCanEdit)) {
|
2016-06-01 13:07:03 +00:00
|
|
|
refreshManageAdminsButton();
|
|
|
|
}
|
2017-04-07 15:07:26 +00:00
|
|
|
if ((update.flags & UpdateFlag::ChannelAmEditor) || (update.flags & UpdateFlag::BlockedUsersChanged)) {
|
|
|
|
refreshManageBlockedUsersButton();
|
|
|
|
}
|
2016-06-01 13:07:03 +00:00
|
|
|
|
|
|
|
contentSizeUpdated();
|
|
|
|
}
|
|
|
|
|
2016-05-31 19:27:11 +00:00
|
|
|
int SettingsWidget::resizeGetHeight(int newWidth) {
|
2016-06-10 11:18:55 +00:00
|
|
|
int newHeight = contentTop() + st::profileEnableNotificationsTop;
|
2016-05-31 19:27:11 +00:00
|
|
|
|
2016-06-02 13:02:55 +00:00
|
|
|
_enableNotifications->moveToLeft(st::profileBlockTitlePosition.x(), newHeight);
|
2016-12-02 19:16:35 +00:00
|
|
|
newHeight += _enableNotifications->heightNoMargins() + st::profileSettingsBlockSkip;
|
2016-06-01 13:07:03 +00:00
|
|
|
|
2016-06-02 13:02:55 +00:00
|
|
|
auto moveLink = [&newHeight, newWidth](Ui::LeftOutlineButton *button) {
|
2016-06-01 13:07:03 +00:00
|
|
|
if (!button) return;
|
|
|
|
|
2016-06-02 13:02:55 +00:00
|
|
|
int left = defaultOutlineButtonLeft();
|
|
|
|
int availableWidth = newWidth - left - st::profileBlockMarginRight;
|
2016-06-01 13:07:03 +00:00
|
|
|
accumulate_min(availableWidth, st::profileBlockOneLineWidthMax);
|
|
|
|
button->resizeToWidth(availableWidth);
|
2016-06-02 13:02:55 +00:00
|
|
|
button->moveToLeft(left, newHeight);
|
2016-06-01 13:07:03 +00:00
|
|
|
newHeight += button->height();
|
|
|
|
};
|
|
|
|
moveLink(_manageAdmins);
|
2017-04-07 15:07:26 +00:00
|
|
|
moveLink(_manageBlockedUsers);
|
2016-06-01 13:07:03 +00:00
|
|
|
moveLink(_inviteLink);
|
|
|
|
|
|
|
|
newHeight += st::profileBlockMarginBottom;
|
2016-05-31 19:27:11 +00:00
|
|
|
return newHeight;
|
|
|
|
}
|
|
|
|
|
2016-06-01 13:07:03 +00:00
|
|
|
void SettingsWidget::refreshButtons() {
|
|
|
|
refreshEnableNotifications();
|
|
|
|
refreshManageAdminsButton();
|
2017-04-07 15:07:26 +00:00
|
|
|
refreshManageBlockedUsersButton();
|
2016-06-01 13:07:03 +00: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 09:20:24 +00:00
|
|
|
_enableNotifications->setChecked(enabled, Ui::Checkbox::NotifyAboutChange::DontNotify);
|
2016-06-01 13:07:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsWidget::refreshManageAdminsButton() {
|
2017-04-07 15:07:26 +00:00
|
|
|
auto hasManageAdmins = [this] {
|
2016-06-01 13:07:03 +00:00
|
|
|
if (auto chat = peer()->asChat()) {
|
|
|
|
return (chat->amCreator() && chat->canEdit());
|
2017-04-07 15:07:26 +00:00
|
|
|
} else if (auto channel = peer()->asMegagroup()) {
|
|
|
|
return channel->amCreator();
|
2016-06-01 13:07:03 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
_manageAdmins.destroy();
|
|
|
|
if (hasManageAdmins()) {
|
2016-11-15 11:56:49 +00:00
|
|
|
_manageAdmins.create(this, lang(lng_profile_manage_admins), st::defaultLeftOutlineButton);
|
2016-06-01 13:07:03 +00:00
|
|
|
_manageAdmins->show();
|
|
|
|
connect(_manageAdmins, SIGNAL(clicked()), this, SLOT(onManageAdmins()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-07 15:07:26 +00:00
|
|
|
void SettingsWidget::refreshManageBlockedUsersButton() {
|
|
|
|
auto hasManageBlockedUsers = [this] {
|
|
|
|
if (auto channel = peer()->asMegagroup()) {
|
|
|
|
return (channel->amCreator() || channel->amEditor()) && (channel->kickedCount() > 0);
|
|
|
|
}
|
|
|
|
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()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-01 13:07:03 +00: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()) {
|
|
|
|
if (channel->amCreator() && !channel->isPublic()) {
|
|
|
|
return lang(channel->inviteLink().isEmpty() ? lng_group_invite_create : lng_group_invite_create_new);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
};
|
|
|
|
auto inviteLinkText = getInviteLinkText();
|
2016-06-14 16:26:41 +00:00
|
|
|
if (inviteLinkText.isEmpty()) {
|
|
|
|
_inviteLink.destroy();
|
|
|
|
} else {
|
2016-11-15 11:56:49 +00:00
|
|
|
_inviteLink.create(this, inviteLinkText, st::defaultLeftOutlineButton);
|
2016-06-01 13:07:03 +00: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 17:07:56 +00:00
|
|
|
Ui::show(Box<ContactsBox>(chat, MembersFilter::Admins));
|
2016-06-01 13:07:03 +00:00
|
|
|
} else if (auto channel = peer()->asChannel()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
Ui::show(Box<MembersBox>(channel, MembersFilter::Admins));
|
2016-06-01 13:07:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-07 15:07:26 +00:00
|
|
|
void SettingsWidget::onManageBlockedUsers() {
|
|
|
|
if (auto channel = peer()->asMegagroup()) {
|
|
|
|
Ui::show(Box<PeerListBox>(std::make_unique<BlockedBoxController>(channel)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-01 13:07:03 +00: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 17:07:56 +00: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 13:07:03 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 19:27:11 +00:00
|
|
|
} // namespace Profile
|