From 173a5046e888836dd3bd951dad3a43d6c3c9d67b Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 17 Nov 2023 00:44:59 +0300 Subject: [PATCH] Added new charts to channel and message statistics. --- Telegram/Resources/langs/lang.strings | 3 +++ Telegram/SourceFiles/api/api_statistics.cpp | 27 +++++++++++++++---- Telegram/SourceFiles/data/data_statistics.h | 4 +++ .../info_statistics_inner_widget.cpp | 16 +++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index f2c9381038..f9576d19ad 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4364,6 +4364,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_chart_title_language" = "Languages"; "lng_chart_title_message_interaction" = "Interactions"; "lng_chart_title_instant_view_interaction" = "IV Interactions"; +"lng_chart_title_reactions_by_emotion" = "Reactions"; +"lng_chart_title_story_interactions" = "Story Interactions"; +"lng_chart_title_story_reactions_by_emotion" = "Story reactions"; "lng_chart_title_group_join" = "Group members"; "lng_chart_title_group_join_by_source" = "New members by source"; diff --git a/Telegram/SourceFiles/api/api_statistics.cpp b/Telegram/SourceFiles/api/api_statistics.cpp index 1f5c093a6e..f8d21c1531 100644 --- a/Telegram/SourceFiles/api/api_statistics.cpp +++ b/Telegram/SourceFiles/api/api_statistics.cpp @@ -110,6 +110,15 @@ constexpr auto kCheckRequestsTimer = 10 * crl::time(1000); .instantViewInteractionGraph = StatisticalGraphFromTL( data.viv_interactions_graph()), + .reactionsByEmotionGraph = StatisticalGraphFromTL( + data.vreactions_by_emotion_graph()), + + .storyInteractionsGraph = StatisticalGraphFromTL( + data.vstory_interactions_graph()), + + .storyReactionsByEmotionGraph = StatisticalGraphFromTL( + data.vstory_reactions_by_emotion_graph()), + .recentMessageInteractions = std::move(recentMessages), }; } @@ -438,12 +447,14 @@ void MessageStatistics::request(Fn done) { } const auto requestFirstPublicForwards = [=]( const Data::StatisticalGraph &messageGraph, + const Data::StatisticalGraph &reactionsGraph, const Data::StatisticsMessageInteractionInfo &info) { _publicForwards.request({}, [=](Data::PublicForwardsSlice slice) { const auto total = slice.total; _firstSlice = std::move(slice); done({ .messageInteractionGraph = messageGraph, + .reactionsByEmotionGraph = reactionsGraph, .publicForwards = total, .privateForwards = info.forwardsCount - total, .views = info.viewsCount, @@ -452,7 +463,8 @@ void MessageStatistics::request(Fn done) { }; const auto requestPrivateForwards = [=]( - const Data::StatisticalGraph &messageGraph) { + const Data::StatisticalGraph &messageGraph, + const Data::StatisticalGraph &reactionsGraph) { api().request(MTPchannels_GetMessages( channel()->inputChannel, MTP_vector( @@ -488,9 +500,12 @@ void MessageStatistics::request(Fn done) { return Data::StatisticsMessageInteractionInfo(); }); - requestFirstPublicForwards(messageGraph, std::move(info)); + requestFirstPublicForwards( + messageGraph, + reactionsGraph, + std::move(info)); }).fail([=](const MTP::Error &error) { - requestFirstPublicForwards(messageGraph, {}); + requestFirstPublicForwards(messageGraph, reactionsGraph, {}); }).send(); }; @@ -499,10 +514,12 @@ void MessageStatistics::request(Fn done) { channel()->inputChannel, MTP_int(_fullId.msg.bare) )).done([=](const MTPstats_MessageStats &result) { + const auto &data = result.data(); requestPrivateForwards( - StatisticalGraphFromTL(result.data().vviews_graph())); + StatisticalGraphFromTL(data.vviews_graph()), + StatisticalGraphFromTL(data.vreactions_by_emotion_graph())); }).fail([=](const MTP::Error &error) { - requestPrivateForwards({}); + requestPrivateForwards({}, {}); }).send(); } diff --git a/Telegram/SourceFiles/data/data_statistics.h b/Telegram/SourceFiles/data/data_statistics.h index ce59e4d58f..46f0009eeb 100644 --- a/Telegram/SourceFiles/data/data_statistics.h +++ b/Telegram/SourceFiles/data/data_statistics.h @@ -67,6 +67,9 @@ struct ChannelStatistics final { StatisticalGraph languageGraph; StatisticalGraph messageInteractionGraph; StatisticalGraph instantViewInteractionGraph; + StatisticalGraph reactionsByEmotionGraph; + StatisticalGraph storyInteractionsGraph; + StatisticalGraph storyReactionsByEmotionGraph; std::vector recentMessageInteractions; @@ -108,6 +111,7 @@ struct MessageStatistics final { return !messageInteractionGraph.chart.empty() || views; } Data::StatisticalGraph messageInteractionGraph; + Data::StatisticalGraph reactionsByEmotionGraph; int publicForwards = 0; int privateForwards = 0; int views = 0; diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp index bbd05b98fe..c62ef93f61 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp @@ -206,6 +206,18 @@ void FillStatistic( stats.channel.instantViewInteractionGraph, tr::lng_chart_title_instant_view_interaction(), Type::DoubleLinear); + addChart( + stats.channel.reactionsByEmotionGraph, + tr::lng_chart_title_reactions_by_emotion(), + Type::Bar); + addChart( + stats.channel.storyInteractionsGraph, + tr::lng_chart_title_story_interactions(), + Type::DoubleLinear); + addChart( + stats.channel.storyReactionsByEmotionGraph, + tr::lng_chart_title_story_reactions_by_emotion(), + Type::Bar); } else if (stats.supergroup) { addChart( stats.supergroup.memberCountGraph, @@ -244,6 +256,10 @@ void FillStatistic( stats.message.messageInteractionGraph, tr::lng_chart_title_message_interaction(), Type::DoubleLinear); + addChart( + stats.message.reactionsByEmotionGraph, + tr::lng_chart_title_reactions_by_emotion(), + Type::Bar); } }