From 5261e962e2575422187f35b09e55b7f240f28090 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 17 Apr 2022 16:28:48 +0300 Subject: [PATCH] Removed Ui::show from menu item for poll stopping. --- .../history/history_inner_widget.cpp | 3 +- .../view/history_view_context_menu.cpp | 36 +++++++++---------- .../history/view/history_view_context_menu.h | 4 +-- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 76a5105070..2966887d20 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2248,7 +2248,8 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { _menu, poll, item, - HistoryView::Context::History); + HistoryView::Context::History, + _controller); } else if (const auto contact = media->sharedContact()) { const auto phone = contact->phoneNumber; _menu->addAction(tr::lng_profile_copy_phone(tr::now), [=] { diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 44ee1713cc..6c260d7deb 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -56,11 +56,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_session_controller.h" #include "lang/lang_keys.h" #include "core/application.h" -#include "mainwidget.h" #include "main/main_session.h" #include "main/main_session_settings.h" #include "apiwrap.h" -#include "facades.h" +#include "facades.h" // LambdaDelayed #include "styles/style_chat.h" #include "styles/style_menu_icons.h" @@ -962,7 +961,8 @@ base::unique_qptr FillContextMenu( } else if (lnkDocument) { AddDocumentActions(result, lnkDocument, item, list); } else if (poll) { - AddPollActions(result, poll, item, list->elementContext()); + const auto context = list->elementContext(); + AddPollActions(result, poll, item, context, list->controller()); } else if (!request.overSelection && view && !hasSelection) { const auto owner = &view->data()->history()->owner(); const auto media = view->media(); @@ -1036,26 +1036,12 @@ void CopyPostLink( : tr::lng_context_about_private_link(tr::now)); } -void StopPoll(not_null session, FullMsgId itemId) { - const auto stop = [=] { - Ui::hideLayer(); - if (const auto item = session->data().message(itemId)) { - session->api().polls().close(item); - } - }; - Ui::show(Ui::MakeConfirmBox({ - .text = tr::lng_polls_stop_warning(), - .confirmed = stop, - .confirmText = tr::lng_polls_stop_sure(), - .cancelText = tr::lng_cancel(), - })); -} - void AddPollActions( not_null menu, not_null poll, not_null item, - Context context) { + Context context, + not_null controller) { if ((context != Context::History) && (context != Context::Replies) && (context != Context::Pinned)) { @@ -1072,7 +1058,17 @@ void AddPollActions( } if (item->canStopPoll()) { menu->addAction(tr::lng_polls_stop(tr::now), [=] { - StopPoll(&poll->session(), itemId); + controller->show(Ui::MakeConfirmBox({ + .text = tr::lng_polls_stop_warning(), + .confirmed = [=](Fn &&close) { + close(); + if (const auto item = poll->owner().message(itemId)) { + controller->session().api().polls().close(item); + } + }, + .confirmText = tr::lng_polls_stop_sure(), + .cancelText = tr::lng_cancel(), + })); }, &st::menuIconStopPoll); } } diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.h b/Telegram/SourceFiles/history/view/history_view_context_menu.h index fc15f956ed..bc9c3d6b2c 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.h +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.h @@ -54,12 +54,12 @@ void CopyPostLink( not_null session, FullMsgId itemId, Context context); -void StopPoll(not_null session, FullMsgId itemId); void AddPollActions( not_null menu, not_null poll, not_null item, - Context context); + Context context, + not_null controller); void AddSaveSoundForNotifications( not_null menu, not_null item,