From 7f3dc27aa9207aa869c76176763b93988cab85af Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 1 Aug 2024 13:28:25 +0200 Subject: [PATCH] Allow removing mini apps from recents. --- .../dialogs/ui/dialogs_suggestions.cpp | 53 +++++++++++++++---- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_suggestions.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_suggestions.cpp index 18ae94b37..a1391e3ba 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_suggestions.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_suggestions.cpp @@ -166,16 +166,17 @@ void FillEntryMenu( .icon = &st::menuIconDeleteAttention, .isAttention = true, }); - - add({ - .text = descriptor.removeAllText, - .handler = RemoveAllConfirm( - descriptor.controller, - descriptor.removeAllConfirm, - descriptor.removeAll), - .icon = &st::menuIconCancelAttention, - .isAttention = true, - }); + if (!descriptor.removeAllText.isEmpty()) { + add({ + .text = descriptor.removeAllText, + .handler = RemoveAllConfirm( + descriptor.controller, + descriptor.removeAllConfirm, + descriptor.removeAll), + .icon = &st::menuIconCancelAttention, + .isAttention = true, + }); + } } RecentRow::RecentRow(not_null peer) @@ -422,6 +423,9 @@ public: not_null window); void prepare() override; + base::unique_qptr rowContextMenu( + QWidget *parent, + not_null row) override; void load(); @@ -1031,6 +1035,35 @@ void RecentAppsController::prepare() { }, _lifetime); } +base::unique_qptr RecentAppsController::rowContextMenu( + QWidget *parent, + not_null row) { + auto result = base::make_unique_q( + parent, + st::popupMenuWithIcons); + const auto peer = row->peer(); + const auto weak = base::make_weak(this); + const auto session = &this->session(); + const auto removeOne = crl::guard(session, [=] { + if (weak) { + const auto rowId = peer->id.value; + if (const auto row = delegate()->peerListFindRow(rowId)) { + setCount(std::max(0, countCurrent() - 1)); + delegate()->peerListRemoveRow(row); + delegate()->peerListRefreshRows(); + } + } + session->topBotApps().remove(peer); + }); + FillEntryMenu(Ui::Menu::CreateAddActionCallback(result), { + .controller = window(), + .peer = peer, + .removeOneText = tr::lng_recent_remove(tr::now), + .removeOne = removeOne, + }); + return result; +} + void RecentAppsController::load() { session().topBotApps().reload(); }