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 8b773e73c0..6041feaa9c 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_cursor_state.h" #include "chat_helpers/message_field.h" #include "boxes/sticker_set_box.h" +#include "ui/boxes/confirm_box.h" #include "base/platform/base_platform_info.h" #include "base/unixtime.h" #include "mainwindow.h" @@ -1233,10 +1234,8 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { } } } else if (fromId) { // suggest to block - if (const auto userId = peerToUser(fromId)) { - if (const auto user = session().data().user(userId)) { - suggestRestrictUser(user); - } + if (const auto participant = session().data().peer(fromId)) { + suggestRestrictParticipant(participant); } } else { // maybe cursor on some text history item? const auto item = view ? view->data().get() : nullptr; @@ -1360,38 +1359,57 @@ void InnerWidget::copyContextText(FullMsgId itemId) { } } -void InnerWidget::suggestRestrictUser(not_null user) { +void InnerWidget::suggestRestrictParticipant( + not_null participant) { Expects(_menu != nullptr); - if (!_channel->isMegagroup() || !_channel->canBanMembers() || _admins.empty()) { + if (!_channel->isMegagroup() + || !_channel->canBanMembers() + || _admins.empty()) { return; } - if (base::contains(_admins, user)) { - if (!base::contains(_adminsCanEdit, user)) { + if (ranges::contains(_admins, participant)) { + if (!ranges::contains(_adminsCanEdit, participant)) { return; } } _menu->addAction(tr::lng_context_restrict_user(tr::now), [=] { + const auto user = participant->asUser(); auto editRestrictions = [=](bool hasAdminRights, ChatRestrictionsInfo currentRights) { auto weak = QPointer(this); - auto weakBox = std::make_shared>(); + auto weakBox = std::make_shared>(); auto box = Box(_channel, user, hasAdminRights, currentRights); box->setSaveCallback([=]( ChatRestrictionsInfo oldRights, ChatRestrictionsInfo newRights) { if (weak) { - weak->restrictUser(user, oldRights, newRights); + weak->restrictParticipant(participant, oldRights, newRights); } if (*weakBox) { (*weakBox)->closeBox(); } }); - *weakBox = QPointer(box.data()); - _controller->show( - std::move(box), - Ui::LayerOption::KeepOther); + *weakBox = _controller->show(std::move(box)); }; - if (base::contains(_admins, user)) { + if (!user) { + const auto text = (_channel->isBroadcast() + ? tr::lng_profile_sure_kick_channel + : tr::lng_profile_sure_kick)( + tr::now, + lt_user, + participant->name); + auto weakBox = std::make_shared>(); + const auto sure = crl::guard(this, [=] { + restrictParticipant( + participant, + ChatRestrictionsInfo(), + ChannelData::KickedRestrictedRights(participant)); + if (*weakBox) { + (*weakBox)->closeBox(); + } + }); + *weakBox = _controller->show(Box(text, sure)); + } else if (base::contains(_admins, user)) { editRestrictions(true, ChatRestrictionsInfo()); } else { _api.request(MTPchannels_GetParticipant( @@ -1420,30 +1438,33 @@ void InnerWidget::suggestRestrictUser(not_null user) { }); } -void InnerWidget::restrictUser( - not_null user, +void InnerWidget::restrictParticipant( + not_null participant, ChatRestrictionsInfo oldRights, ChatRestrictionsInfo newRights) { const auto done = [=](ChatRestrictionsInfo newRights) { - restrictUserDone(user, newRights); + restrictParticipantDone(participant, newRights); }; const auto callback = SaveRestrictedCallback( _channel, - user, + participant, crl::guard(this, done), nullptr); callback(oldRights, newRights); } -void InnerWidget::restrictUserDone( - not_null user, +void InnerWidget::restrictParticipantDone( + not_null participant, ChatRestrictionsInfo rights) { if (rights.flags) { _admins.erase( - std::remove(_admins.begin(), _admins.end(), user), + std::remove(_admins.begin(), _admins.end(), participant), _admins.end()); _adminsCanEdit.erase( - std::remove(_adminsCanEdit.begin(), _adminsCanEdit.end(), user), + std::remove( + _adminsCanEdit.begin(), + _adminsCanEdit.end(), + participant), _adminsCanEdit.end()); } _downLoaded = false; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h index 0f3d1d959e..65792b3d4a 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.h @@ -204,9 +204,14 @@ private: void copyContextText(FullMsgId itemId); void copySelectedText(); TextForMimeData getSelectedText() const; - void suggestRestrictUser(not_null user); - void restrictUser(not_null user, ChatRestrictionsInfo oldRights, ChatRestrictionsInfo newRights); - void restrictUserDone(not_null user, ChatRestrictionsInfo rights); + void suggestRestrictParticipant(not_null participant); + void restrictParticipant( + not_null participant, + ChatRestrictionsInfo oldRights, + ChatRestrictionsInfo newRights); + void restrictParticipantDone( + not_null participant, + ChatRestrictionsInfo rights); void requestAdmins(); void checkPreloadMore(); diff --git a/Telegram/SourceFiles/history/history_item.cpp b/Telegram/SourceFiles/history/history_item.cpp index 93ab1cd463..613ba2b996 100644 --- a/Telegram/SourceFiles/history/history_item.cpp +++ b/Telegram/SourceFiles/history/history_item.cpp @@ -727,10 +727,7 @@ bool HistoryItem::suggestReport() const { bool HistoryItem::suggestBanReport() const { const auto channel = history()->peer->asChannel(); - const auto fromUser = from()->asUser(); - if (!channel - || !fromUser - || !channel->canRestrictParticipant(fromUser)) { + if (!channel || !channel->canRestrictParticipant(from())) { return false; } return !isPost() && !out();