diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 6d224100c2..7a1aacdeb7 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2722,6 +2722,22 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { return; } const auto controller = _controller; + const auto canViewMessageStats = [&](HistoryItem *item) { + if (!item + || item->isService() + || !peerIsChannel(item->fullId().peer) + || _peer->isMegagroup()) { + return false; + } + const auto channel = _peer->asChannel(); + if (!channel) { + return false; + } + constexpr auto kMinViewsCount = 10; + return ((channel->flags() & ChannelDataFlag::CanGetStatistics) + || (channel->canPostMessages() + && item->viewsCount() >= kMinViewsCount)); + }; const auto addItemActions = [&]( HistoryItem *item, HistoryItem *albumPartItem) { @@ -2806,24 +2822,16 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { Window::ToggleMessagePinned(controller, pinItemId, !isPinned); }), isPinned ? &st::menuIconUnpin : &st::menuIconPin); } - if (!item->isService() - && peerIsChannel(itemId.peer) - && !_peer->isMegagroup()) { - constexpr auto kMinViewsCount = 10; - if (const auto channel = _peer->asChannel()) { - if ((channel->flags() & ChannelDataFlag::CanGetStatistics) - || (channel->canPostMessages() - && item->viewsCount() >= kMinViewsCount)) { - 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); - } - } + if (canViewMessageStats(item)) { + const auto channel = _peer->asChannel(); + 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) { @@ -3323,7 +3331,8 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { item, HistoryView::Context::History, _controller, - !pollOptionLink.isEmpty()); + !pollOptionLink.isEmpty(), + canViewMessageStats(item)); } 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 dbaed5f6bc..5e6b57675b 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -1932,7 +1932,8 @@ void AddPollActions( not_null item, Context context, not_null controller, - bool skipRetractVote) { + bool skipRetractVote, + bool skipViewStats) { { constexpr auto kRadio = "\xf0\x9f\x94\x98"; const auto radio = QString::fromUtf8(kRadio); @@ -1959,7 +1960,7 @@ void AddPollActions( return; } const auto itemId = item->fullId(); - if (poll->canViewStats() && item->isRegular()) { + if (poll->canViewStats() && item->isRegular() && !skipViewStats) { menu->addAction(tr::lng_polls_view_stats(tr::now), [=] { ShowPollStatsBox(controller, itemId); }, &st::menuIconStats); diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.h b/Telegram/SourceFiles/history/view/history_view_context_menu.h index 308f5e5685..d1b5857185 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.h +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.h @@ -98,7 +98,8 @@ void AddPollActions( not_null item, Context context, not_null controller, - bool skipRetractVote = false); + bool skipRetractVote = false, + bool skipViewStats = false); void AddSaveSoundForNotifications( not_null menu, not_null item,