Skip to content

Commit

Permalink
Allow removing mini apps from recents.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Aug 1, 2024
1 parent 51fc104 commit 7f3dc27
Showing 1 changed file with 43 additions and 10 deletions.
53 changes: 43 additions & 10 deletions Telegram/SourceFiles/dialogs/ui/dialogs_suggestions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PeerData*> peer)
Expand Down Expand Up @@ -422,6 +423,9 @@ class RecentAppsController final
not_null<Window::SessionController*> window);

void prepare() override;
base::unique_qptr<Ui::PopupMenu> rowContextMenu(
QWidget *parent,
not_null<PeerListRow*> row) override;

void load();

Expand Down Expand Up @@ -1031,6 +1035,35 @@ void RecentAppsController::prepare() {
}, _lifetime);
}

base::unique_qptr<Ui::PopupMenu> RecentAppsController::rowContextMenu(
QWidget *parent,
not_null<PeerListRow*> row) {
auto result = base::make_unique_q<Ui::PopupMenu>(
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();
}
Expand Down

0 comments on commit 7f3dc27

Please sign in to comment.