mirror of
https://github.com/telegramdesktop/tdesktop
synced 2024-12-28 01:23:09 +00:00
Allow to see admin / banned rights for everyone.
Even if you can't edit admin / banned rights you can see them.
This commit is contained in:
parent
9344504781
commit
58a592ba47
@ -1278,6 +1278,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
"lng_rights_edit_admin_header" = "What can this admin do?";
|
||||
"lng_rights_about_add_admins_yes" = "This admin will be able to add new admins with the same (or more limited) permissions.";
|
||||
"lng_rights_about_add_admins_no" = "This admin will not be able to add new admins.";
|
||||
"lng_rights_about_admin_cant_edit" = "You cannot edit rights of this admin.";
|
||||
"lng_rights_user_restrictions" = "User restrictions";
|
||||
"lng_rights_user_restrictions_header" = "What can this user do?";
|
||||
|
||||
|
@ -211,9 +211,8 @@ void EditParticipantBox::resizeToContent() {
|
||||
setDimensions(_inner->width(), qMin(_inner->height(), st::boxMaxListHeight));
|
||||
}
|
||||
|
||||
EditAdminBox::EditAdminBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, const MTPChannelAdminRights &rights, base::lambda<void(MTPChannelAdminRights, MTPChannelAdminRights)> callback) : EditParticipantBox(nullptr, channel, user, (rights.c_channelAdminRights().vflags.v != 0))
|
||||
, _oldRights(rights)
|
||||
, _saveCallback(std::move(callback)) {
|
||||
EditAdminBox::EditAdminBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, const MTPChannelAdminRights &rights) : EditParticipantBox(nullptr, channel, user, (rights.c_channelAdminRights().vflags.v != 0))
|
||||
, _oldRights(rights) {
|
||||
auto dependency = [this](Flag dependent, Flag dependency) {
|
||||
_dependencies.push_back(std::make_pair(dependent, dependency));
|
||||
};
|
||||
@ -248,6 +247,9 @@ void EditAdminBox::prepare() {
|
||||
control->setDisabled(true); // Grey out options that we don't have ourselves.
|
||||
}
|
||||
}
|
||||
if (!canSave()) {
|
||||
control->setDisabled(true);
|
||||
}
|
||||
_checkboxes.emplace(flags, control);
|
||||
};
|
||||
if (channel()->isMegagroup()) {
|
||||
@ -276,25 +278,29 @@ void EditAdminBox::prepare() {
|
||||
refreshAboutAddAdminsText();
|
||||
}
|
||||
|
||||
addButton(langFactory(lng_settings_save), [this] {
|
||||
if (!_saveCallback) {
|
||||
return;
|
||||
}
|
||||
auto newFlags = MTPDchannelAdminRights::Flags(0);
|
||||
for (auto &&checkbox : _checkboxes) {
|
||||
if (checkbox.second->checked()) {
|
||||
newFlags |= checkbox.first;
|
||||
} else {
|
||||
newFlags &= ~checkbox.first;
|
||||
if (canSave()) {
|
||||
addButton(langFactory(lng_settings_save), [this] {
|
||||
if (!_saveCallback) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!channel()->amCreator()) {
|
||||
// Leave only rights that we have so we could save them.
|
||||
newFlags &= channel()->adminRights().vflags.v;
|
||||
}
|
||||
_saveCallback(_oldRights, MTP_channelAdminRights(MTP_flags(newFlags)));
|
||||
});
|
||||
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
||||
auto newFlags = MTPDchannelAdminRights::Flags(0);
|
||||
for (auto &&checkbox : _checkboxes) {
|
||||
if (checkbox.second->checked()) {
|
||||
newFlags |= checkbox.first;
|
||||
} else {
|
||||
newFlags &= ~checkbox.first;
|
||||
}
|
||||
}
|
||||
if (!channel()->amCreator()) {
|
||||
// Leave only rights that we have so we could save them.
|
||||
newFlags &= channel()->adminRights().vflags.v;
|
||||
}
|
||||
_saveCallback(_oldRights, MTP_channelAdminRights(MTP_flags(newFlags)));
|
||||
});
|
||||
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
||||
} else {
|
||||
addButton(langFactory(lng_box_ok), [this] { closeBox(); });
|
||||
}
|
||||
|
||||
applyDependencies(nullptr);
|
||||
for (auto &&checkbox : _checkboxes) {
|
||||
@ -311,14 +317,20 @@ void EditAdminBox::applyDependencies(QPointer<Ui::Checkbox> changed) {
|
||||
void EditAdminBox::refreshAboutAddAdminsText() {
|
||||
auto addAdmins = _checkboxes.find(Flag::f_add_admins);
|
||||
t_assert(addAdmins != _checkboxes.end());
|
||||
_aboutAddAdmins->setText(lang(addAdmins->second->checked() ? lng_rights_about_add_admins_yes : lng_rights_about_add_admins_no));
|
||||
|
||||
auto text = [this, addAdmins] {
|
||||
if (!canSave()) {
|
||||
return lang(lng_rights_about_admin_cant_edit);
|
||||
} else if (addAdmins->second->checked()) {
|
||||
return lang(lng_rights_about_add_admins_yes);
|
||||
}
|
||||
return lang(lng_rights_about_add_admins_no);
|
||||
};
|
||||
_aboutAddAdmins->setText(text());
|
||||
resizeToContent();
|
||||
}
|
||||
|
||||
EditRestrictedBox::EditRestrictedBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, bool hasAdminRights, const MTPChannelBannedRights &rights, base::lambda<void(MTPChannelBannedRights, MTPChannelBannedRights)> callback) : EditParticipantBox(nullptr, channel, user, hasAdminRights)
|
||||
, _oldRights(rights)
|
||||
, _saveCallback(std::move(callback)) {
|
||||
EditRestrictedBox::EditRestrictedBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, bool hasAdminRights, const MTPChannelBannedRights &rights) : EditParticipantBox(nullptr, channel, user, hasAdminRights)
|
||||
, _oldRights(rights) {
|
||||
auto dependency = [this](Flag dependent, Flag dependency) {
|
||||
_dependencies.push_back(std::make_pair(dependent, dependency));
|
||||
};
|
||||
@ -351,6 +363,9 @@ void EditRestrictedBox::prepare() {
|
||||
subscribe(control->checkedChanged, [this, control](bool checked) {
|
||||
InvokeQueued(this, [this, control] { applyDependencies(control); });
|
||||
});
|
||||
if (!canSave()) {
|
||||
control->setDisabled(true);
|
||||
}
|
||||
_checkboxes.emplace(flags, control);
|
||||
};
|
||||
addCheckbox(Flag::f_view_messages, lang(lng_rights_chat_read));
|
||||
@ -365,21 +380,25 @@ void EditRestrictedBox::prepare() {
|
||||
|
||||
//addControl(object_ptr<Ui::LinkButton>(this, lang(lng_rights_chat_banned_block), st::boxLinkButton));
|
||||
|
||||
addButton(langFactory(lng_settings_save), [this] {
|
||||
if (!_saveCallback) {
|
||||
return;
|
||||
}
|
||||
auto newFlags = MTPDchannelBannedRights::Flags(0);
|
||||
for (auto &&checkbox : _checkboxes) {
|
||||
if (checkbox.second->checked()) {
|
||||
newFlags &= ~checkbox.first;
|
||||
} else {
|
||||
newFlags |= checkbox.first;
|
||||
if (canSave()) {
|
||||
addButton(langFactory(lng_settings_save), [this] {
|
||||
if (!_saveCallback) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
_saveCallback(_oldRights, MTP_channelBannedRights(MTP_flags(newFlags), MTP_int(getRealUntilValue())));
|
||||
});
|
||||
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
||||
auto newFlags = MTPDchannelBannedRights::Flags(0);
|
||||
for (auto &&checkbox : _checkboxes) {
|
||||
if (checkbox.second->checked()) {
|
||||
newFlags &= ~checkbox.first;
|
||||
} else {
|
||||
newFlags |= checkbox.first;
|
||||
}
|
||||
}
|
||||
_saveCallback(_oldRights, MTP_channelBannedRights(MTP_flags(newFlags), MTP_int(getRealUntilValue())));
|
||||
});
|
||||
addButton(langFactory(lng_cancel), [this] { closeBox(); });
|
||||
} else {
|
||||
addButton(langFactory(lng_box_ok), [this] { closeBox(); });
|
||||
}
|
||||
|
||||
applyDependencies(nullptr);
|
||||
for (auto &&checkbox : _checkboxes) {
|
||||
@ -439,7 +458,13 @@ void EditRestrictedBox::createUntilGroup() {
|
||||
|
||||
void EditRestrictedBox::createUntilVariants() {
|
||||
auto addVariant = [this](int value, const QString &text) {
|
||||
if (!canSave() && _untilGroup->value() != value) {
|
||||
return;
|
||||
}
|
||||
_untilVariants.push_back(addControl(object_ptr<Ui::Radiobutton>(this, _untilGroup, value, text, st::defaultBoxCheckbox), st::rightsToggleMargin));
|
||||
if (!canSave()) {
|
||||
_untilVariants.back()->setDisabled(true);
|
||||
}
|
||||
};
|
||||
auto addCustomVariant = [this, addVariant](TimeId until, TimeId from, TimeId to) {
|
||||
if (!ChannelData::IsRestrictedForever(until) && until > from && until <= to) {
|
||||
|
@ -71,7 +71,11 @@ private:
|
||||
|
||||
class EditAdminBox : public EditParticipantBox {
|
||||
public:
|
||||
EditAdminBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, const MTPChannelAdminRights &rights, base::lambda<void(MTPChannelAdminRights, MTPChannelAdminRights)> callback);
|
||||
EditAdminBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, const MTPChannelAdminRights &rights);
|
||||
|
||||
void setSaveCallback(base::lambda<void(MTPChannelAdminRights, MTPChannelAdminRights)> callback) {
|
||||
_saveCallback = std::move(callback);
|
||||
}
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
@ -82,6 +86,9 @@ private:
|
||||
|
||||
static MTPChannelAdminRights DefaultRights(gsl::not_null<ChannelData*> channel);
|
||||
|
||||
bool canSave() const {
|
||||
return !!_saveCallback;
|
||||
}
|
||||
void applyDependencies(QPointer<Ui::Checkbox> changed);
|
||||
void refreshAboutAddAdminsText();
|
||||
|
||||
@ -99,7 +106,11 @@ private:
|
||||
|
||||
class EditRestrictedBox : public EditParticipantBox {
|
||||
public:
|
||||
EditRestrictedBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, bool hasAdminRights, const MTPChannelBannedRights &rights, base::lambda<void(MTPChannelBannedRights, MTPChannelBannedRights)> callback);
|
||||
EditRestrictedBox(QWidget*, gsl::not_null<ChannelData*> channel, gsl::not_null<UserData*> user, bool hasAdminRights, const MTPChannelBannedRights &rights);
|
||||
|
||||
void setSaveCallback(base::lambda<void(MTPChannelBannedRights, MTPChannelBannedRights)> callback) {
|
||||
_saveCallback = std::move(callback);
|
||||
}
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
@ -110,6 +121,9 @@ private:
|
||||
|
||||
static MTPChannelBannedRights DefaultRights(gsl::not_null<ChannelData*> channel);
|
||||
|
||||
bool canSave() const {
|
||||
return !!_saveCallback;
|
||||
}
|
||||
void applyDependencies(QPointer<Ui::Checkbox> changed);
|
||||
void showRestrictUntil();
|
||||
void setRestrictUntil(TimeId until);
|
||||
|
@ -282,10 +282,11 @@ void MembersBox::Inner::actionPressed(Member &row) {
|
||||
} else {
|
||||
auto currentRights = _rows[_kickSelected].adminRights;
|
||||
auto weak = QPointer<Inner>(this);
|
||||
auto box = std::make_shared<QPointer<EditAdminBox>>(nullptr);
|
||||
_kickBox = *box = Ui::show(Box<EditAdminBox>(_channel, user, currentRights, [channel = _channel, weak, user, box](const MTPChannelAdminRights &oldRights, const MTPChannelAdminRights &newRights) {
|
||||
if (*box) {
|
||||
(*box)->closeBox();
|
||||
auto weakBox = std::make_shared<QPointer<EditAdminBox>>(nullptr);
|
||||
auto box = Box<EditAdminBox>(_channel, user, currentRights);
|
||||
box->setSaveCallback([channel = _channel, weak, user, weakBox](const MTPChannelAdminRights &oldRights, const MTPChannelAdminRights &newRights) {
|
||||
if (*weakBox) {
|
||||
(*weakBox)->closeBox();
|
||||
}
|
||||
MTP::send(MTPchannels_EditAdmin(channel->inputChannel, user->inputUser, newRights), ::rpcDone([channel, weak, user, oldRights, newRights](const MTPUpdates &result, mtpRequestId req) {
|
||||
if (App::main()) App::main()->sentUpdatesReceived(result);
|
||||
@ -294,7 +295,8 @@ void MembersBox::Inner::actionPressed(Member &row) {
|
||||
weak->editAdminDone(user, newRights);
|
||||
}
|
||||
}), weak ? weak->rpcFail(&Inner::kickFail) : RPCFailHandlerPtr());
|
||||
}), KeepOtherLayers);
|
||||
});
|
||||
_kickBox = *weakBox = Ui::show(std::move(box), KeepOtherLayers);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1020,15 +1020,17 @@ void InnerWidget::suggestRestrictUser(gsl::not_null<UserData*> user) {
|
||||
_menu->addAction(lang(lng_context_restrict_user), [this, user] {
|
||||
auto editRestrictions = [user, this](bool hasAdminRights, const MTPChannelBannedRights ¤tRights) {
|
||||
auto weak = QPointer<InnerWidget>(this);
|
||||
auto box = std::make_shared<QPointer<EditRestrictedBox>>();
|
||||
*box = Ui::show(Box<EditRestrictedBox>(_channel, user, hasAdminRights, currentRights, [user, weak, box](const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights) {
|
||||
auto weakBox = std::make_shared<QPointer<EditRestrictedBox>>();
|
||||
auto box = Box<EditRestrictedBox>(_channel, user, hasAdminRights, currentRights);
|
||||
box->setSaveCallback([user, weak, weakBox](const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights) {
|
||||
if (weak) {
|
||||
weak->restrictUser(user, oldRights, newRights);
|
||||
}
|
||||
if (*box) {
|
||||
(*box)->closeBox();
|
||||
if (*weakBox) {
|
||||
(*weakBox)->closeBox();
|
||||
}
|
||||
}), KeepOtherLayers);
|
||||
});
|
||||
*weakBox = Ui::show(std::move(box), KeepOtherLayers);
|
||||
};
|
||||
if (base::contains(_admins, user)) {
|
||||
editRestrictions(true, MTP_channelBannedRights(MTP_flags(0), MTP_int(0)));
|
||||
|
@ -76,13 +76,15 @@ void GroupMembersWidget::editAdmin(gsl::not_null<UserData*> user) {
|
||||
auto hasAdminRights = (currentRightsIt != megagroup->mgInfo->lastAdmins.cend());
|
||||
auto currentRights = hasAdminRights ? currentRightsIt->rights : MTP_channelAdminRights(MTP_flags(0));
|
||||
auto weak = QPointer<GroupMembersWidget>(this);
|
||||
Ui::show(Box<EditAdminBox>(megagroup, user, currentRights, [weak, megagroup, user](const MTPChannelAdminRights &oldRights, const MTPChannelAdminRights &newRights) {
|
||||
auto box = Box<EditAdminBox>(megagroup, user, currentRights);
|
||||
box->setSaveCallback([weak, megagroup, user](const MTPChannelAdminRights &oldRights, const MTPChannelAdminRights &newRights) {
|
||||
Ui::hideLayer();
|
||||
MTP::send(MTPchannels_EditAdmin(megagroup->inputChannel, user->inputUser, newRights), rpcDone([weak, megagroup, user, oldRights, newRights](const MTPUpdates &result) {
|
||||
if (App::main()) App::main()->sentUpdatesReceived(result);
|
||||
megagroup->applyEditAdmin(user, oldRights, newRights);
|
||||
}));
|
||||
}));
|
||||
});
|
||||
Ui::show(std::move(box));
|
||||
}
|
||||
|
||||
void GroupMembersWidget::restrictUser(gsl::not_null<UserData*> user) {
|
||||
@ -93,13 +95,15 @@ void GroupMembersWidget::restrictUser(gsl::not_null<UserData*> user) {
|
||||
auto defaultRestricted = MegagroupInfo::Restricted { MTP_channelBannedRights(MTP_flags(0), MTP_int(0)) };
|
||||
auto currentRights = megagroup->mgInfo->lastRestricted.value(user, defaultRestricted).rights;
|
||||
auto hasAdminRights = megagroup->mgInfo->lastAdmins.find(user) != megagroup->mgInfo->lastAdmins.cend();
|
||||
Ui::show(Box<EditRestrictedBox>(megagroup, user, hasAdminRights, currentRights, [megagroup, user](const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights) {
|
||||
auto box = Box<EditRestrictedBox>(megagroup, user, hasAdminRights, currentRights);
|
||||
box->setSaveCallback([megagroup, user](const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights) {
|
||||
Ui::hideLayer();
|
||||
MTP::send(MTPchannels_EditBanned(megagroup->inputChannel, user->inputUser, newRights), rpcDone([megagroup, user, oldRights, newRights](const MTPUpdates &result) {
|
||||
if (App::main()) App::main()->sentUpdatesReceived(result);
|
||||
megagroup->applyEditBanned(user, oldRights, newRights);
|
||||
}));
|
||||
}));
|
||||
});
|
||||
Ui::show(std::move(box));
|
||||
}
|
||||
|
||||
void GroupMembersWidget::removePeer(PeerData *selectedPeer) {
|
||||
|
@ -185,28 +185,37 @@ void ParticipantsBoxController::loadMoreRows() {
|
||||
setDescriptionText((_role == Role::Restricted) ? lang(lng_group_blocked_list_about) : QString());
|
||||
}
|
||||
auto &participants = result.c_channels_channelParticipants();
|
||||
App::feedUsers(participants.vusers);
|
||||
App::feedUsers(participants.vusers);
|
||||
|
||||
auto &list = participants.vparticipants.v;
|
||||
if (list.isEmpty()) {
|
||||
// To be sure - wait for a whole empty result list.
|
||||
_allLoaded = true;
|
||||
} else {
|
||||
for_const (auto &participant, list) {
|
||||
++_offset;
|
||||
HandleParticipant(participant, _role, &_additional, [this](gsl::not_null<UserData*> user) {
|
||||
appendRow(user);
|
||||
});
|
||||
}
|
||||
}
|
||||
delegate()->peerListRefreshRows();
|
||||
auto &list = participants.vparticipants.v;
|
||||
if (list.isEmpty()) {
|
||||
// To be sure - wait for a whole empty result list.
|
||||
_allLoaded = true;
|
||||
} else {
|
||||
for_const (auto &participant, list) {
|
||||
++_offset;
|
||||
HandleParticipant(participant, _role, &_additional, [this](gsl::not_null<UserData*> user) {
|
||||
appendRow(user);
|
||||
});
|
||||
}
|
||||
}
|
||||
delegate()->peerListRefreshRows();
|
||||
}).fail([this](const RPCError &error) {
|
||||
_loadRequestId = 0;
|
||||
}).send();
|
||||
}
|
||||
|
||||
void ParticipantsBoxController::rowClicked(gsl::not_null<PeerListRow*> row) {
|
||||
Ui::showPeerHistoryAsync(row->peer()->id, ShowAtUnreadMsgId);
|
||||
auto user = row->peer()->asUser();
|
||||
Expects(user != nullptr);
|
||||
|
||||
if (_role == Role::Admins) {
|
||||
showAdmin(user);
|
||||
} else if (_role == Role::Restricted || _role == Role::Kicked) {
|
||||
showRestricted(user);
|
||||
} else {
|
||||
Ui::showPeerProfile(row->peer());
|
||||
}
|
||||
}
|
||||
|
||||
void ParticipantsBoxController::rowActionClicked(gsl::not_null<PeerListRow*> row) {
|
||||
@ -214,31 +223,38 @@ void ParticipantsBoxController::rowActionClicked(gsl::not_null<PeerListRow*> row
|
||||
Expects(user != nullptr);
|
||||
|
||||
if (_role == Role::Admins) {
|
||||
editAdmin(user);
|
||||
showAdmin(user);
|
||||
} else if (_role == Role::Restricted) {
|
||||
editRestricted(user);
|
||||
showRestricted(user);
|
||||
} else {
|
||||
removeKicked(row, user);
|
||||
}
|
||||
}
|
||||
|
||||
void ParticipantsBoxController::editAdmin(gsl::not_null<UserData*> user) {
|
||||
if (_additional.adminCanEdit.find(user) == _additional.adminCanEdit.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
void ParticipantsBoxController::showAdmin(gsl::not_null<UserData*> user) {
|
||||
auto it = _additional.adminRights.find(user);
|
||||
t_assert(it != _additional.adminRights.cend());
|
||||
if (it == _additional.adminRights.cend()) {
|
||||
if (user != _additional.creator) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto currentRights = (user == _additional.creator)
|
||||
? MTP_channelAdminRights(MTP_flags(~MTPDchannelAdminRights::Flag::f_add_admins | MTPDchannelAdminRights::Flag::f_add_admins))
|
||||
: it->second;
|
||||
auto weak = base::weak_unique_ptr<ParticipantsBoxController>(this);
|
||||
_editBox = Ui::show(Box<EditAdminBox>(_channel, user, it->second, [channel = _channel.get(), user, weak](const MTPChannelAdminRights &oldRights, const MTPChannelAdminRights &newRights) {
|
||||
MTP::send(MTPchannels_EditAdmin(channel->inputChannel, user->inputUser, newRights), rpcDone([channel, user, weak, oldRights, newRights](const MTPUpdates &result) {
|
||||
AuthSession::Current().api().applyUpdates(result);
|
||||
channel->applyEditAdmin(user, oldRights, newRights);
|
||||
if (weak) {
|
||||
weak->editAdminDone(user, newRights);
|
||||
}
|
||||
}));
|
||||
}), KeepOtherLayers);
|
||||
auto box = Box<EditAdminBox>(_channel, user, currentRights);
|
||||
if (_additional.adminCanEdit.find(user) != _additional.adminCanEdit.end()) {
|
||||
box->setSaveCallback([channel = _channel.get(), user, weak](const MTPChannelAdminRights &oldRights, const MTPChannelAdminRights &newRights) {
|
||||
MTP::send(MTPchannels_EditAdmin(channel->inputChannel, user->inputUser, newRights), rpcDone([channel, user, weak, oldRights, newRights](const MTPUpdates &result) {
|
||||
AuthSession::Current().api().applyUpdates(result);
|
||||
channel->applyEditAdmin(user, oldRights, newRights);
|
||||
if (weak) {
|
||||
weak->editAdminDone(user, newRights);
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
_editBox = Ui::show(std::move(box), KeepOtherLayers);
|
||||
}
|
||||
|
||||
void ParticipantsBoxController::editAdminDone(gsl::not_null<UserData*> user, const MTPChannelAdminRights &rights) {
|
||||
@ -272,20 +288,26 @@ void ParticipantsBoxController::editAdminDone(gsl::not_null<UserData*> user, con
|
||||
delegate()->peerListRefreshRows();
|
||||
}
|
||||
|
||||
void ParticipantsBoxController::editRestricted(gsl::not_null<UserData*> user) {
|
||||
void ParticipantsBoxController::showRestricted(gsl::not_null<UserData*> user) {
|
||||
auto it = _additional.restrictedRights.find(user);
|
||||
t_assert(it != _additional.restrictedRights.cend());
|
||||
if (it == _additional.restrictedRights.cend()) {
|
||||
return;
|
||||
}
|
||||
auto weak = base::weak_unique_ptr<ParticipantsBoxController>(this);
|
||||
auto hasAdminRights = false;
|
||||
_editBox = Ui::show(Box<EditRestrictedBox>(_channel, user, hasAdminRights, it->second, [megagroup = _channel.get(), user, weak](const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights) {
|
||||
MTP::send(MTPchannels_EditBanned(megagroup->inputChannel, user->inputUser, newRights), rpcDone([megagroup, user, weak, oldRights, newRights](const MTPUpdates &result) {
|
||||
AuthSession::Current().api().applyUpdates(result);
|
||||
megagroup->applyEditBanned(user, oldRights, newRights);
|
||||
if (weak) {
|
||||
weak->editRestrictedDone(user, newRights);
|
||||
}
|
||||
}));
|
||||
}), KeepOtherLayers);
|
||||
auto box = Box<EditRestrictedBox>(_channel, user, hasAdminRights, it->second);
|
||||
if (_channel->canBanMembers()) {
|
||||
box->setSaveCallback([megagroup = _channel.get(), user, weak](const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights) {
|
||||
MTP::send(MTPchannels_EditBanned(megagroup->inputChannel, user->inputUser, newRights), rpcDone([megagroup, user, weak, oldRights, newRights](const MTPUpdates &result) {
|
||||
AuthSession::Current().api().applyUpdates(result);
|
||||
megagroup->applyEditBanned(user, oldRights, newRights);
|
||||
if (weak) {
|
||||
weak->editRestrictedDone(user, newRights);
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
_editBox = Ui::show(std::move(box), KeepOtherLayers);
|
||||
}
|
||||
|
||||
void ParticipantsBoxController::editRestrictedDone(gsl::not_null<UserData*> user, const MTPChannelBannedRights &rights) {
|
||||
@ -379,7 +401,7 @@ std::unique_ptr<PeerListRow> ParticipantsBoxController::createRow(gsl::not_null<
|
||||
}
|
||||
}
|
||||
if (_role == Role::Restricted || (_role == Role::Admins && _additional.adminCanEdit.find(user) != _additional.adminCanEdit.end())) {
|
||||
row->setActionLink(lang(lng_profile_edit_permissions));
|
||||
// row->setActionLink(lang(lng_profile_edit_permissions));
|
||||
} else if (_role == Role::Kicked) {
|
||||
row->setActionLink(lang(lng_blocked_list_unblock));
|
||||
}
|
||||
@ -575,8 +597,8 @@ void AddParticipantBoxController::loadMoreRows() {
|
||||
void AddParticipantBoxController::rowClicked(gsl::not_null<PeerListRow*> row) {
|
||||
auto user = row->peer()->asUser();
|
||||
switch (_role) {
|
||||
case Role::Admins: return editAdmin(user);
|
||||
case Role::Restricted: return editRestricted(user);
|
||||
case Role::Admins: return showAdmin(user);
|
||||
case Role::Restricted: return showRestricted(user);
|
||||
case Role::Kicked: return kickUser(user);
|
||||
}
|
||||
Unexpected("Role in AddParticipantBoxController::rowClicked()");
|
||||
@ -604,8 +626,8 @@ bool AddParticipantBoxController::checkInfoLoaded(gsl::not_null<UserData*> user,
|
||||
return false;
|
||||
}
|
||||
|
||||
void AddParticipantBoxController::editAdmin(gsl::not_null<UserData*> user, bool sure) {
|
||||
if (!checkInfoLoaded(user, [this, user] { editAdmin(user); })) {
|
||||
void AddParticipantBoxController::showAdmin(gsl::not_null<UserData*> user, bool sure) {
|
||||
if (!checkInfoLoaded(user, [this, user] { showAdmin(user); })) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -617,13 +639,11 @@ void AddParticipantBoxController::editAdmin(gsl::not_null<UserData*> user, bool
|
||||
// Check restrictions.
|
||||
auto weak = base::weak_unique_ptr<AddParticipantBoxController>(this);
|
||||
auto alreadyIt = _additional.adminRights.find(user);
|
||||
auto currentRights = MTP_channelAdminRights(MTP_flags(0));
|
||||
if (alreadyIt != _additional.adminRights.end() || _additional.creator == user) {
|
||||
auto currentRights = (_additional.creator == user)
|
||||
? MTP_channelAdminRights(MTP_flags(~MTPDchannelAdminRights::Flag::f_add_admins | MTPDchannelAdminRights::Flag::f_add_admins))
|
||||
: MTP_channelAdminRights(MTP_flags(0));
|
||||
if (alreadyIt != _additional.adminRights.end()) {
|
||||
// The user is already an admin.
|
||||
if (_additional.adminCanEdit.find(user) == _additional.adminCanEdit.end() || _additional.creator == user) {
|
||||
Ui::show(Box<InformBox>(lang(lng_error_cant_edit_admin)), KeepOtherLayers);
|
||||
return;
|
||||
}
|
||||
currentRights = alreadyIt->second;
|
||||
} else if (_additional.kicked.find(user) != _additional.kicked.end()) {
|
||||
// The user is banned.
|
||||
@ -632,7 +652,7 @@ void AddParticipantBoxController::editAdmin(gsl::not_null<UserData*> user, bool
|
||||
if (!sure) {
|
||||
_editBox = Ui::show(Box<ConfirmBox>(lang(lng_sure_add_admin_unban), [weak, user] {
|
||||
if (weak) {
|
||||
weak->editAdmin(user, true);
|
||||
weak->showAdmin(user, true);
|
||||
}
|
||||
}), KeepOtherLayers);
|
||||
return;
|
||||
@ -651,7 +671,7 @@ void AddParticipantBoxController::editAdmin(gsl::not_null<UserData*> user, bool
|
||||
if (!sure) {
|
||||
_editBox = Ui::show(Box<ConfirmBox>(lang(lng_sure_add_admin_unban), [weak, user] {
|
||||
if (weak) {
|
||||
weak->editAdmin(user, true);
|
||||
weak->showAdmin(user, true);
|
||||
}
|
||||
}), KeepOtherLayers);
|
||||
return;
|
||||
@ -666,7 +686,7 @@ void AddParticipantBoxController::editAdmin(gsl::not_null<UserData*> user, bool
|
||||
if (!sure) {
|
||||
_editBox = Ui::show(Box<ConfirmBox>(lang(lng_sure_add_admin_invite), [weak, user] {
|
||||
if (weak) {
|
||||
weak->editAdmin(user, true);
|
||||
weak->showAdmin(user, true);
|
||||
}
|
||||
}), KeepOtherLayers);
|
||||
return;
|
||||
@ -677,29 +697,36 @@ void AddParticipantBoxController::editAdmin(gsl::not_null<UserData*> user, bool
|
||||
}
|
||||
}
|
||||
|
||||
// Finally edit the admin.
|
||||
_editBox = Ui::show(Box<EditAdminBox>(_channel, user, currentRights, [channel = _channel.get(), user, weak](const MTPChannelAdminRights &oldRights, const MTPChannelAdminRights &newRights) {
|
||||
MTP::send(MTPchannels_EditAdmin(channel->inputChannel, user->inputUser, newRights), rpcDone([channel, user, weak, oldRights, newRights](const MTPUpdates &result) {
|
||||
AuthSession::Current().api().applyUpdates(result);
|
||||
channel->applyEditAdmin(user, oldRights, newRights);
|
||||
if (weak) {
|
||||
weak->editAdminDone(user, newRights);
|
||||
}
|
||||
}), rpcFail([channel, weak](const RPCError &error) {
|
||||
if (MTP::isDefaultHandledError(error)) {
|
||||
return false;
|
||||
}
|
||||
if (error.type() == qstr("USER_NOT_MUTUAL_CONTACT")) {
|
||||
Ui::show(Box<InformBox>(PeerFloodErrorText(channel->isMegagroup() ? PeerFloodType::InviteGroup : PeerFloodType::InviteChannel)), KeepOtherLayers);
|
||||
} else if (error.type() == qstr("BOT_GROUPS_BLOCKED")) {
|
||||
Ui::show(Box<InformBox>(lang(lng_error_cant_add_bot)), KeepOtherLayers);
|
||||
}
|
||||
if (weak && weak->_editBox) {
|
||||
weak->_editBox->closeBox();
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
}), KeepOtherLayers);
|
||||
// Finally show the admin.
|
||||
auto canNotEdit = (_additional.creator == user)
|
||||
|| ((alreadyIt != _additional.adminRights.end())
|
||||
&& (_additional.adminCanEdit.find(user) == _additional.adminCanEdit.end()));
|
||||
auto box = Box<EditAdminBox>(_channel, user, currentRights);
|
||||
if (!canNotEdit) {
|
||||
box->setSaveCallback([channel = _channel.get(), user, weak](const MTPChannelAdminRights &oldRights, const MTPChannelAdminRights &newRights) {
|
||||
MTP::send(MTPchannels_EditAdmin(channel->inputChannel, user->inputUser, newRights), rpcDone([channel, user, weak, oldRights, newRights](const MTPUpdates &result) {
|
||||
AuthSession::Current().api().applyUpdates(result);
|
||||
channel->applyEditAdmin(user, oldRights, newRights);
|
||||
if (weak) {
|
||||
weak->editAdminDone(user, newRights);
|
||||
}
|
||||
}), rpcFail([channel, weak](const RPCError &error) {
|
||||
if (MTP::isDefaultHandledError(error)) {
|
||||
return false;
|
||||
}
|
||||
if (error.type() == qstr("USER_NOT_MUTUAL_CONTACT")) {
|
||||
Ui::show(Box<InformBox>(PeerFloodErrorText(channel->isMegagroup() ? PeerFloodType::InviteGroup : PeerFloodType::InviteChannel)), KeepOtherLayers);
|
||||
} else if (error.type() == qstr("BOT_GROUPS_BLOCKED")) {
|
||||
Ui::show(Box<InformBox>(lang(lng_error_cant_add_bot)), KeepOtherLayers);
|
||||
}
|
||||
if (weak && weak->_editBox) {
|
||||
weak->_editBox->closeBox();
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
});
|
||||
}
|
||||
_editBox = Ui::show(std::move(box), KeepOtherLayers);
|
||||
}
|
||||
|
||||
void AddParticipantBoxController::editAdminDone(gsl::not_null<UserData*> user, const MTPChannelAdminRights &rights) {
|
||||
@ -724,8 +751,8 @@ void AddParticipantBoxController::editAdminDone(gsl::not_null<UserData*> user, c
|
||||
}
|
||||
}
|
||||
|
||||
void AddParticipantBoxController::editRestricted(gsl::not_null<UserData*> user, bool sure) {
|
||||
if (!checkInfoLoaded(user, [this, user] { editRestricted(user); })) {
|
||||
void AddParticipantBoxController::showRestricted(gsl::not_null<UserData*> user, bool sure) {
|
||||
if (!checkInfoLoaded(user, [this, user] { showRestricted(user); })) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -749,7 +776,7 @@ void AddParticipantBoxController::editRestricted(gsl::not_null<UserData*> user,
|
||||
if (!sure) {
|
||||
_editBox = Ui::show(Box<ConfirmBox>(lang(lng_sure_ban_admin), [weak, user] {
|
||||
if (weak) {
|
||||
weak->editRestricted(user, true);
|
||||
weak->showRestricted(user, true);
|
||||
}
|
||||
}), KeepOtherLayers);
|
||||
return;
|
||||
@ -761,11 +788,13 @@ void AddParticipantBoxController::editRestricted(gsl::not_null<UserData*> user,
|
||||
}
|
||||
|
||||
// Finally edit the restricted.
|
||||
_editBox = Ui::show(Box<EditRestrictedBox>(_channel, user, hasAdminRights, currentRights, [user, weak](const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights) {
|
||||
auto box = Box<EditRestrictedBox>(_channel, user, hasAdminRights, currentRights);
|
||||
box->setSaveCallback([user, weak](const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights) {
|
||||
if (weak) {
|
||||
weak->restrictUserSure(user, oldRights, newRights);
|
||||
}
|
||||
}), KeepOtherLayers);
|
||||
});
|
||||
_editBox = Ui::show(std::move(box), KeepOtherLayers);
|
||||
}
|
||||
|
||||
void AddParticipantBoxController::restrictUserSure(gsl::not_null<UserData*> user, const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights) {
|
||||
|
@ -64,9 +64,9 @@ public:
|
||||
static void HandleParticipant(const MTPChannelParticipant &participant, Role role, gsl::not_null<Additional*> additional, Callback callback);
|
||||
|
||||
private:
|
||||
void editAdmin(gsl::not_null<UserData*> user);
|
||||
void showAdmin(gsl::not_null<UserData*> user);
|
||||
void editAdminDone(gsl::not_null<UserData*> user, const MTPChannelAdminRights &rights);
|
||||
void editRestricted(gsl::not_null<UserData*> user);
|
||||
void showRestricted(gsl::not_null<UserData*> user);
|
||||
void editRestrictedDone(gsl::not_null<UserData*> user, const MTPChannelBannedRights &rights);
|
||||
void removeKicked(gsl::not_null<PeerListRow*> row, gsl::not_null<UserData*> user);
|
||||
bool appendRow(gsl::not_null<UserData*> user);
|
||||
@ -149,9 +149,9 @@ private:
|
||||
template <typename Callback>
|
||||
bool checkInfoLoaded(gsl::not_null<UserData*> user, Callback callback);
|
||||
|
||||
void editAdmin(gsl::not_null<UserData*> user, bool sure = false);
|
||||
void showAdmin(gsl::not_null<UserData*> user, bool sure = false);
|
||||
void editAdminDone(gsl::not_null<UserData*> user, const MTPChannelAdminRights &rights);
|
||||
void editRestricted(gsl::not_null<UserData*> user, bool sure = false);
|
||||
void showRestricted(gsl::not_null<UserData*> user, bool sure = false);
|
||||
void editRestrictedDone(gsl::not_null<UserData*> user, const MTPChannelBannedRights &rights);
|
||||
void kickUser(gsl::not_null<UserData*> user, bool sure = false);
|
||||
void restrictUserSure(gsl::not_null<UserData*> user, const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights);
|
||||
|
Loading…
Reference in New Issue
Block a user