diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index ce3c2a1f18..560575b25d 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -127,7 +127,9 @@ void SaveChannelAdmin( )).done([=](const MTPUpdates &result) { channel->session().api().applyUpdates(result); channel->applyEditAdmin(user, oldRights, newRights); - onDone(); + if (onDone) { + onDone(); + } }).fail([=](const RPCError &error) { if (error.type() == qstr("USER_NOT_MUTUAL_CONTACT")) { Ui::show( @@ -147,7 +149,9 @@ void SaveChannelAdmin( : lng_error_admin_limit_channel)), LayerOption::KeepOther); } - onFail(); + if (onFail) { + onFail(); + } }).send(); } @@ -165,9 +169,13 @@ void SaveChannelRestriction( )).done([=](const MTPUpdates &result) { channel->session().api().applyUpdates(result); channel->applyEditBanned(user, oldRights, newRights); - onDone(); + if (onDone) { + onDone(); + } }).fail([=](const RPCError &error) { - onFail(); + if (onFail) { + onFail(); + } }).send(); } @@ -183,7 +191,7 @@ Fn channel) { SaveChannelAdmin( channel, @@ -226,7 +234,7 @@ Fn channel) { SaveChannelRestriction( channel, diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index d51e767396..0cdc13e811 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -33,6 +33,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/file_utilities.h" #include "lang/lang_keys.h" #include "boxes/peers/edit_participant_box.h" +#include "boxes/peers/edit_participants_box.h" #include "data/data_session.h" #include "data/data_photo.h" #include "data/data_document.h" @@ -1189,15 +1190,19 @@ void InnerWidget::suggestRestrictUser(not_null user) { }); } -void InnerWidget::restrictUser(not_null user, const MTPChatBannedRights &oldRights, const MTPChatBannedRights &newRights) { - auto weak = QPointer(this); - MTP::send(MTPchannels_EditBanned(_channel->inputChannel, user->inputUser, newRights), rpcDone([megagroup = _channel.get(), user, weak, oldRights, newRights](const MTPUpdates &result) { - Auth().api().applyUpdates(result); - megagroup->applyEditBanned(user, oldRights, newRights); - if (weak) { - weak->restrictUserDone(user, newRights); - } - })); +void InnerWidget::restrictUser( + not_null user, + const MTPChatBannedRights &oldRights, + const MTPChatBannedRights &newRights) { + const auto done = [=](const MTPChatBannedRights &newRights) { + restrictUserDone(user, newRights); + }; + const auto callback = SaveRestrictedCallback( + _channel, + user, + crl::guard(this, done), + nullptr); + callback(oldRights, newRights); } void InnerWidget::restrictUserDone(not_null user, const MTPChatBannedRights &rights) {