From f88eee80472eedf81a6b9d382f02b294a261ff7f Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 17 Nov 2023 04:10:45 +0300 Subject: [PATCH] Added reactions count to overview in statistics info. --- Telegram/SourceFiles/api/api_statistics.cpp | 9 +++++++++ Telegram/SourceFiles/data/data_statistics.h | 2 ++ .../info/statistics/info_statistics_inner_widget.cpp | 12 +++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/api/api_statistics.cpp b/Telegram/SourceFiles/api/api_statistics.cpp index f8d21c1531..70226fa06b 100644 --- a/Telegram/SourceFiles/api/api_statistics.cpp +++ b/Telegram/SourceFiles/api/api_statistics.cpp @@ -458,6 +458,7 @@ void MessageStatistics::request(Fn done) { .publicForwards = total, .privateForwards = info.forwardsCount - total, .views = info.viewsCount, + .reactions = info.reactionsCount, }); }); }; @@ -474,6 +475,13 @@ void MessageStatistics::request(Fn done) { const auto process = [&](const MTPVector &messages) { const auto &message = messages.v.front(); return message.match([&](const MTPDmessage &data) { + auto reactionsCount = 0; + if (const auto tlReactions = data.vreactions()) { + const auto &tlCounts = tlReactions->data().vresults(); + for (const auto &tlCount : tlCounts.v) { + reactionsCount += tlCount.data().vcount().v; + } + } return Data::StatisticsMessageInteractionInfo{ .messageId = IdFromMessage(message), .viewsCount = data.vviews() @@ -482,6 +490,7 @@ void MessageStatistics::request(Fn done) { .forwardsCount = data.vforwards() ? data.vforwards()->v : 0, + .reactionsCount = reactionsCount, }; }, [](const MTPDmessageEmpty &) { return Data::StatisticsMessageInteractionInfo(); diff --git a/Telegram/SourceFiles/data/data_statistics.h b/Telegram/SourceFiles/data/data_statistics.h index 46f0009eeb..50b0694dd3 100644 --- a/Telegram/SourceFiles/data/data_statistics.h +++ b/Telegram/SourceFiles/data/data_statistics.h @@ -15,6 +15,7 @@ struct StatisticsMessageInteractionInfo final { MsgId messageId; int viewsCount = 0; int forwardsCount = 0; + int reactionsCount = 0; }; struct StatisticsMessageSenderInfo final { @@ -115,6 +116,7 @@ struct MessageStatistics final { int publicForwards = 0; int privateForwards = 0; int views = 0; + int reactions = 0; }; struct AnyStatistics final { diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp index c62ef93f61..950b27ca36 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp @@ -394,12 +394,12 @@ void FillOverview( const auto bottomLeftLabel = isChannel ? addPrimary(channel.meanViewCount) : isMessage - ? addPrimary({ .value = float64(stats.message.privateForwards) }) + ? addPrimary({ .value = float64(stats.message.reactions) }) : addPrimary(supergroup.viewerCount); const auto bottomRightLabel = isChannel ? addPrimary(channel.meanShareCount) : isMessage - ? addPrimary({ .value = -1. }) + ? addPrimary({ .value = float64(stats.message.privateForwards) }) : addPrimary(supergroup.senderCount); if (const auto &s = channel) { addSub( @@ -448,10 +448,16 @@ void FillOverview( {}, tr::lng_stats_overview_message_public_shares); } - if (s.privateForwards >= 0) { + if (s.reactions >= 0) { addSub( bottomLeftLabel, {}, + tr::lng_manage_peer_reactions); + } + if (s.privateForwards >= 0) { + addSub( + bottomRightLabel, + {}, tr::lng_stats_overview_message_private_shares); } }