From 343261d6ae89647b6f3184021d9a2f7ec373b8f3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 1 Mar 2026 21:17:58 +0400 Subject: [PATCH] Fix actions in members dropdown. --- .../boxes/peers/edit_participants_box.cpp | 68 +++++++++---------- .../boxes/peers/edit_participants_box.h | 1 - 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index 14e4a687ba..ea68824def 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -1802,7 +1802,7 @@ void ParticipantsBoxController::rowElementClicked( const auto peer = _peer; const auto currentRank = _additional.memberRank(user); const auto isSelf = user->isSelf(); - _editBox = show->show(Box( + show->show(Box( EditCustomRankBox, show, peer, @@ -1916,22 +1916,23 @@ base::unique_qptr ParticipantsBoxController::rowContextMenu( : (currentRank.isEmpty() ? tr::lng_context_add_member_tag(tr::now) : tr::lng_context_edit_member_tag(tr::now)); + const auto weak = base::make_weak(this); result->addAction( actionText, - crl::guard(this, [=] { - _editBox = show->show(Box( + [=] { + show->show(Box( EditCustomRankBox, show, peer, user, currentRank, canEditSelf, - crl::guard(this, [=](const QString &rank) { + crl::guard(weak, [=](const QString &rank) { _additional.applyMemberRankLocally(user, rank); recomputeTypeFor(user); refreshRows(); }))); - }), + }, (currentRank.isEmpty() ? &st::menuIconTagAdd : &st::menuIconTagEdit)); @@ -2109,8 +2110,33 @@ void ParticipantsBoxController::editRestrictedDone( void ParticipantsBoxController::kickParticipant(not_null participant) { const auto user = participant->asUser(); + const auto kickFrom = _peer; + const auto restrictedRights = _additional.restrictedRights(participant); + const auto removeLocal = crl::guard(this, [=] { + const auto id = participant->id; + if (const auto row = delegate()->peerListFindRow(id.value)) { + delegate()->peerListRemoveRow(row); + refreshRows(); + } + }); + const auto kick = [=] { + const auto currentRights = restrictedRights + ? *restrictedRights + : ChatRestrictionsInfo(); + removeLocal(); + auto &session = kickFrom->session(); + if (const auto chat = kickFrom->asChat()) { + session.api().chatParticipants().kick(chat, participant); + } else if (const auto channel = kickFrom->asChannel()) { + session.api().chatParticipants().kick( + channel, + participant, + currentRights); + } + }; + if (user && user->isInaccessible()) { - return kickParticipantSure(participant); + return kick(); } const auto text = ((_peer->isChat() || _peer->isMegagroup()) ? tr::lng_profile_sure_kick @@ -2118,12 +2144,10 @@ void ParticipantsBoxController::kickParticipant(not_null participant) tr::now, lt_user, user ? user->firstName : participant->name()); - _editBox = showBox( + showBox( Ui::MakeConfirmBox({ .text = text, - .confirmed = crl::guard(this, [=] { - kickParticipantSure(participant); - }), + .confirmed = [=](Fn close) { kick(); close(); }, .confirmText = tr::lng_box_remove(), })); } @@ -2138,30 +2162,6 @@ void ParticipantsBoxController::unkickParticipant(not_null user) { _peer->session().api().chatParticipants().add(show, _peer, { 1, user }); } -void ParticipantsBoxController::kickParticipantSure( - not_null participant) { - _editBox = nullptr; - - const auto restrictedRights = _additional.restrictedRights(participant); - const auto currentRights = restrictedRights - ? *restrictedRights - : ChatRestrictionsInfo(); - - if (const auto row = delegate()->peerListFindRow(participant->id.value)) { - delegate()->peerListRemoveRow(row); - refreshRows(); - } - auto &session = _peer->session(); - if (const auto chat = _peer->asChat()) { - session.api().chatParticipants().kick(chat, participant); - } else if (const auto channel = _peer->asChannel()) { - session.api().chatParticipants().kick( - channel, - participant, - currentRights); - } -} - void ParticipantsBoxController::removeAdmin(not_null user) { _editBox = showBox( Ui::MakeConfirmBox({ diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.h b/Telegram/SourceFiles/boxes/peers/edit_participants_box.h index 1d8a14dd80..6d40bec4c2 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.h +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.h @@ -298,7 +298,6 @@ private: void removeKickedWithRow(not_null participant); void removeKicked(not_null participant); void kickParticipant(not_null participant); - void kickParticipantSure(not_null participant); void unkickParticipant(not_null user); void removeAdmin(not_null user); void removeAdminSure(not_null user);