diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 02dadf73bc..95e6f76d83 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -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?"; diff --git a/Telegram/SourceFiles/boxes/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/edit_participant_box.cpp index 7c105ba5e6..0e369d6c65 100644 --- a/Telegram/SourceFiles/boxes/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_participant_box.cpp @@ -211,9 +211,8 @@ void EditParticipantBox::resizeToContent() { setDimensions(_inner->width(), qMin(_inner->height(), st::boxMaxListHeight)); } -EditAdminBox::EditAdminBox(QWidget*, gsl::not_null channel, gsl::not_null user, const MTPChannelAdminRights &rights, base::lambda callback) : EditParticipantBox(nullptr, channel, user, (rights.c_channelAdminRights().vflags.v != 0)) -, _oldRights(rights) -, _saveCallback(std::move(callback)) { +EditAdminBox::EditAdminBox(QWidget*, gsl::not_null channel, gsl::not_null 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 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 channel, gsl::not_null user, bool hasAdminRights, const MTPChannelBannedRights &rights, base::lambda callback) : EditParticipantBox(nullptr, channel, user, hasAdminRights) -, _oldRights(rights) -, _saveCallback(std::move(callback)) { +EditRestrictedBox::EditRestrictedBox(QWidget*, gsl::not_null channel, gsl::not_null 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(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(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) { diff --git a/Telegram/SourceFiles/boxes/edit_participant_box.h b/Telegram/SourceFiles/boxes/edit_participant_box.h index d37355d1ab..6b6519fba2 100644 --- a/Telegram/SourceFiles/boxes/edit_participant_box.h +++ b/Telegram/SourceFiles/boxes/edit_participant_box.h @@ -71,7 +71,11 @@ private: class EditAdminBox : public EditParticipantBox { public: - EditAdminBox(QWidget*, gsl::not_null channel, gsl::not_null user, const MTPChannelAdminRights &rights, base::lambda callback); + EditAdminBox(QWidget*, gsl::not_null channel, gsl::not_null user, const MTPChannelAdminRights &rights); + + void setSaveCallback(base::lambda callback) { + _saveCallback = std::move(callback); + } protected: void prepare() override; @@ -82,6 +86,9 @@ private: static MTPChannelAdminRights DefaultRights(gsl::not_null channel); + bool canSave() const { + return !!_saveCallback; + } void applyDependencies(QPointer changed); void refreshAboutAddAdminsText(); @@ -99,7 +106,11 @@ private: class EditRestrictedBox : public EditParticipantBox { public: - EditRestrictedBox(QWidget*, gsl::not_null channel, gsl::not_null user, bool hasAdminRights, const MTPChannelBannedRights &rights, base::lambda callback); + EditRestrictedBox(QWidget*, gsl::not_null channel, gsl::not_null user, bool hasAdminRights, const MTPChannelBannedRights &rights); + + void setSaveCallback(base::lambda callback) { + _saveCallback = std::move(callback); + } protected: void prepare() override; @@ -110,6 +121,9 @@ private: static MTPChannelBannedRights DefaultRights(gsl::not_null channel); + bool canSave() const { + return !!_saveCallback; + } void applyDependencies(QPointer changed); void showRestrictUntil(); void setRestrictUntil(TimeId until); diff --git a/Telegram/SourceFiles/boxes/members_box.cpp b/Telegram/SourceFiles/boxes/members_box.cpp index 33587ad1dd..57278bbc08 100644 --- a/Telegram/SourceFiles/boxes/members_box.cpp +++ b/Telegram/SourceFiles/boxes/members_box.cpp @@ -282,10 +282,11 @@ void MembersBox::Inner::actionPressed(Member &row) { } else { auto currentRights = _rows[_kickSelected].adminRights; auto weak = QPointer(this); - auto box = std::make_shared>(nullptr); - _kickBox = *box = Ui::show(Box(_channel, user, currentRights, [channel = _channel, weak, user, box](const MTPChannelAdminRights &oldRights, const MTPChannelAdminRights &newRights) { - if (*box) { - (*box)->closeBox(); + auto weakBox = std::make_shared>(nullptr); + auto box = Box(_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); } } diff --git a/Telegram/SourceFiles/history/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/history_admin_log_inner.cpp index 083d635dc8..6eeb361063 100644 --- a/Telegram/SourceFiles/history/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/history_admin_log_inner.cpp @@ -1020,15 +1020,17 @@ void InnerWidget::suggestRestrictUser(gsl::not_null user) { _menu->addAction(lang(lng_context_restrict_user), [this, user] { auto editRestrictions = [user, this](bool hasAdminRights, const MTPChannelBannedRights ¤tRights) { auto weak = QPointer(this); - auto box = std::make_shared>(); - *box = Ui::show(Box(_channel, user, hasAdminRights, currentRights, [user, weak, box](const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights) { + auto weakBox = std::make_shared>(); + auto box = Box(_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))); diff --git a/Telegram/SourceFiles/profile/profile_block_group_members.cpp b/Telegram/SourceFiles/profile/profile_block_group_members.cpp index 312094b2ed..452759843e 100644 --- a/Telegram/SourceFiles/profile/profile_block_group_members.cpp +++ b/Telegram/SourceFiles/profile/profile_block_group_members.cpp @@ -76,13 +76,15 @@ void GroupMembersWidget::editAdmin(gsl::not_null user) { auto hasAdminRights = (currentRightsIt != megagroup->mgInfo->lastAdmins.cend()); auto currentRights = hasAdminRights ? currentRightsIt->rights : MTP_channelAdminRights(MTP_flags(0)); auto weak = QPointer(this); - Ui::show(Box(megagroup, user, currentRights, [weak, megagroup, user](const MTPChannelAdminRights &oldRights, const MTPChannelAdminRights &newRights) { + auto box = Box(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 user) { @@ -93,13 +95,15 @@ void GroupMembersWidget::restrictUser(gsl::not_null 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(megagroup, user, hasAdminRights, currentRights, [megagroup, user](const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights) { + auto box = Box(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) { diff --git a/Telegram/SourceFiles/profile/profile_channel_controllers.cpp b/Telegram/SourceFiles/profile/profile_channel_controllers.cpp index 10f11fcf7f..3672ae0641 100644 --- a/Telegram/SourceFiles/profile/profile_channel_controllers.cpp +++ b/Telegram/SourceFiles/profile/profile_channel_controllers.cpp @@ -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 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 user) { + appendRow(user); + }); + } +} +delegate()->peerListRefreshRows(); }).fail([this](const RPCError &error) { _loadRequestId = 0; }).send(); } void ParticipantsBoxController::rowClicked(gsl::not_null 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 row) { @@ -214,31 +223,38 @@ void ParticipantsBoxController::rowActionClicked(gsl::not_null 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 user) { - if (_additional.adminCanEdit.find(user) == _additional.adminCanEdit.end()) { - return; - } - +void ParticipantsBoxController::showAdmin(gsl::not_null 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(this); - _editBox = Ui::show(Box(_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(_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 user, const MTPChannelAdminRights &rights) { @@ -272,20 +288,26 @@ void ParticipantsBoxController::editAdminDone(gsl::not_null user, con delegate()->peerListRefreshRows(); } -void ParticipantsBoxController::editRestricted(gsl::not_null user) { +void ParticipantsBoxController::showRestricted(gsl::not_null 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(this); auto hasAdminRights = false; - _editBox = Ui::show(Box(_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(_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 user, const MTPChannelBannedRights &rights) { @@ -379,7 +401,7 @@ std::unique_ptr 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 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 user, return false; } -void AddParticipantBoxController::editAdmin(gsl::not_null user, bool sure) { - if (!checkInfoLoaded(user, [this, user] { editAdmin(user); })) { +void AddParticipantBoxController::showAdmin(gsl::not_null user, bool sure) { + if (!checkInfoLoaded(user, [this, user] { showAdmin(user); })) { return; } @@ -617,13 +639,11 @@ void AddParticipantBoxController::editAdmin(gsl::not_null user, bool // Check restrictions. auto weak = base::weak_unique_ptr(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(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 user, bool if (!sure) { _editBox = Ui::show(Box(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 user, bool if (!sure) { _editBox = Ui::show(Box(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 user, bool if (!sure) { _editBox = Ui::show(Box(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 user, bool } } - // Finally edit the admin. - _editBox = Ui::show(Box(_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(PeerFloodErrorText(channel->isMegagroup() ? PeerFloodType::InviteGroup : PeerFloodType::InviteChannel)), KeepOtherLayers); - } else if (error.type() == qstr("BOT_GROUPS_BLOCKED")) { - Ui::show(Box(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(_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(PeerFloodErrorText(channel->isMegagroup() ? PeerFloodType::InviteGroup : PeerFloodType::InviteChannel)), KeepOtherLayers); + } else if (error.type() == qstr("BOT_GROUPS_BLOCKED")) { + Ui::show(Box(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 user, const MTPChannelAdminRights &rights) { @@ -724,8 +751,8 @@ void AddParticipantBoxController::editAdminDone(gsl::not_null user, c } } -void AddParticipantBoxController::editRestricted(gsl::not_null user, bool sure) { - if (!checkInfoLoaded(user, [this, user] { editRestricted(user); })) { +void AddParticipantBoxController::showRestricted(gsl::not_null user, bool sure) { + if (!checkInfoLoaded(user, [this, user] { showRestricted(user); })) { return; } @@ -749,7 +776,7 @@ void AddParticipantBoxController::editRestricted(gsl::not_null user, if (!sure) { _editBox = Ui::show(Box(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 user, } // Finally edit the restricted. - _editBox = Ui::show(Box(_channel, user, hasAdminRights, currentRights, [user, weak](const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights) { + auto box = Box(_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 user, const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights) { diff --git a/Telegram/SourceFiles/profile/profile_channel_controllers.h b/Telegram/SourceFiles/profile/profile_channel_controllers.h index 365969c666..0c6c553640 100644 --- a/Telegram/SourceFiles/profile/profile_channel_controllers.h +++ b/Telegram/SourceFiles/profile/profile_channel_controllers.h @@ -64,9 +64,9 @@ public: static void HandleParticipant(const MTPChannelParticipant &participant, Role role, gsl::not_null additional, Callback callback); private: - void editAdmin(gsl::not_null user); + void showAdmin(gsl::not_null user); void editAdminDone(gsl::not_null user, const MTPChannelAdminRights &rights); - void editRestricted(gsl::not_null user); + void showRestricted(gsl::not_null user); void editRestrictedDone(gsl::not_null user, const MTPChannelBannedRights &rights); void removeKicked(gsl::not_null row, gsl::not_null user); bool appendRow(gsl::not_null user); @@ -149,9 +149,9 @@ private: template bool checkInfoLoaded(gsl::not_null user, Callback callback); - void editAdmin(gsl::not_null user, bool sure = false); + void showAdmin(gsl::not_null user, bool sure = false); void editAdminDone(gsl::not_null user, const MTPChannelAdminRights &rights); - void editRestricted(gsl::not_null user, bool sure = false); + void showRestricted(gsl::not_null user, bool sure = false); void editRestrictedDone(gsl::not_null user, const MTPChannelBannedRights &rights); void kickUser(gsl::not_null user, bool sure = false); void restrictUserSure(gsl::not_null user, const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights);