Use one place for saving restrictions.

This commit is contained in:
John Preston 2019-01-16 13:12:31 +04:00
parent 287b3509ab
commit 04350af96f
2 changed files with 28 additions and 15 deletions

View File

@ -127,7 +127,9 @@ void SaveChannelAdmin(
)).done([=](const MTPUpdates &result) { )).done([=](const MTPUpdates &result) {
channel->session().api().applyUpdates(result); channel->session().api().applyUpdates(result);
channel->applyEditAdmin(user, oldRights, newRights); channel->applyEditAdmin(user, oldRights, newRights);
onDone(); if (onDone) {
onDone();
}
}).fail([=](const RPCError &error) { }).fail([=](const RPCError &error) {
if (error.type() == qstr("USER_NOT_MUTUAL_CONTACT")) { if (error.type() == qstr("USER_NOT_MUTUAL_CONTACT")) {
Ui::show( Ui::show(
@ -147,7 +149,9 @@ void SaveChannelAdmin(
: lng_error_admin_limit_channel)), : lng_error_admin_limit_channel)),
LayerOption::KeepOther); LayerOption::KeepOther);
} }
onFail(); if (onFail) {
onFail();
}
}).send(); }).send();
} }
@ -165,9 +169,13 @@ void SaveChannelRestriction(
)).done([=](const MTPUpdates &result) { )).done([=](const MTPUpdates &result) {
channel->session().api().applyUpdates(result); channel->session().api().applyUpdates(result);
channel->applyEditBanned(user, oldRights, newRights); channel->applyEditBanned(user, oldRights, newRights);
onDone(); if (onDone) {
onDone();
}
}).fail([=](const RPCError &error) { }).fail([=](const RPCError &error) {
onFail(); if (onFail) {
onFail();
}
}).send(); }).send();
} }
@ -183,7 +191,7 @@ Fn<void(
return [=]( return [=](
const MTPChatAdminRights &oldRights, const MTPChatAdminRights &oldRights,
const MTPChatAdminRights &newRights) { const MTPChatAdminRights &newRights) {
const auto done = [=] { onDone(newRights); }; const auto done = [=] { if (onDone) onDone(newRights); };
const auto saveForChannel = [=](not_null<ChannelData*> channel) { const auto saveForChannel = [=](not_null<ChannelData*> channel) {
SaveChannelAdmin( SaveChannelAdmin(
channel, channel,
@ -226,7 +234,7 @@ Fn<void(
return [=]( return [=](
const MTPChatBannedRights &oldRights, const MTPChatBannedRights &oldRights,
const MTPChatBannedRights &newRights) { const MTPChatBannedRights &newRights) {
const auto done = [=] { onDone(newRights); }; const auto done = [=] { if (onDone) onDone(newRights); };
const auto saveForChannel = [=](not_null<ChannelData*> channel) { const auto saveForChannel = [=](not_null<ChannelData*> channel) {
SaveChannelRestriction( SaveChannelRestriction(
channel, channel,

View File

@ -33,6 +33,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/file_utilities.h" #include "core/file_utilities.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "boxes/peers/edit_participant_box.h" #include "boxes/peers/edit_participant_box.h"
#include "boxes/peers/edit_participants_box.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_photo.h" #include "data/data_photo.h"
#include "data/data_document.h" #include "data/data_document.h"
@ -1189,15 +1190,19 @@ void InnerWidget::suggestRestrictUser(not_null<UserData*> user) {
}); });
} }
void InnerWidget::restrictUser(not_null<UserData*> user, const MTPChatBannedRights &oldRights, const MTPChatBannedRights &newRights) { void InnerWidget::restrictUser(
auto weak = QPointer<InnerWidget>(this); not_null<UserData*> user,
MTP::send(MTPchannels_EditBanned(_channel->inputChannel, user->inputUser, newRights), rpcDone([megagroup = _channel.get(), user, weak, oldRights, newRights](const MTPUpdates &result) { const MTPChatBannedRights &oldRights,
Auth().api().applyUpdates(result); const MTPChatBannedRights &newRights) {
megagroup->applyEditBanned(user, oldRights, newRights); const auto done = [=](const MTPChatBannedRights &newRights) {
if (weak) { restrictUserDone(user, newRights);
weak->restrictUserDone(user, newRights); };
} const auto callback = SaveRestrictedCallback(
})); _channel,
user,
crl::guard(this, done),
nullptr);
callback(oldRights, newRights);
} }
void InnerWidget::restrictUserDone(not_null<UserData*> user, const MTPChatBannedRights &rights) { void InnerWidget::restrictUserDone(not_null<UserData*> user, const MTPChatBannedRights &rights) {