From 0aa1031402ce83ff8ec242e68acbcd1eea333bf6 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 22 Oct 2023 11:09:04 +0300 Subject: [PATCH] Added ability to open message statistics from context menu. --- .../history/history_inner_widget.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index d296beeba..a575ce312 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -45,6 +45,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_controller.h" #include "window/window_peer_menu.h" #include "window/notifications_manager.h" +#include "info/info_memento.h" +#include "info/statistics/info_statistics_widget.h" #include "boxes/about_sponsored_box.h" #include "boxes/delete_messages_box.h" #include "boxes/report_messages_box.h" @@ -2212,11 +2214,26 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { if (pinItem->canPin()) { const auto isPinned = pinItem->isPinned(); const auto pinItemId = pinItem->fullId(); - const auto controller = _controller; _menu->addAction(isPinned ? tr::lng_context_unpin_msg(tr::now) : tr::lng_context_pin_msg(tr::now), crl::guard(controller, [=] { Window::ToggleMessagePinned(controller, pinItemId, !isPinned); }), isPinned ? &st::menuIconUnpin : &st::menuIconPin); } + if (!item->isService() + && peerIsChannel(itemId.peer) + && !_peer->isMegagroup()) { + if (const auto channel = _peer->asChannel()) { + if (channel->flags() & ChannelDataFlag::CanGetStatistics) { + auto callback = crl::guard(controller, [=] { + controller->showSection( + Info::Statistics::Make(channel, itemId)); + }); + _menu->addAction( + tr::lng_stats_title(tr::now), + std::move(callback), + &st::menuIconStats); + } + } + } }; const auto addPhotoActions = [&](not_null photo, HistoryItem *item) { const auto media = photo->activeMediaView();