From dfe55b26a29263e1b15fc56e189a993b20d36089 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 28 Nov 2023 04:41:56 +0300 Subject: [PATCH] Added statistical values for stories to overview in statistics info. --- Telegram/Resources/langs/lang.strings | 4 + Telegram/SourceFiles/api/api_statistics.cpp | 7 ++ Telegram/SourceFiles/data/data_statistics.h | 3 + .../info_statistics_inner_widget.cpp | 74 +++++++++++++++---- 4 files changed, 74 insertions(+), 14 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 82573c229..7217f5c87 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4330,6 +4330,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_stats_overview_member_count" = "Followers"; "lng_stats_overview_mean_view_count" = "Views Per Post"; "lng_stats_overview_mean_share_count" = "Shared Per Post"; +"lng_stats_overview_mean_reactions_count" = "Reactions Per Post"; +"lng_stats_overview_mean_story_view_count" = "Views Per Story"; +"lng_stats_overview_mean_story_share_count" = "Shared Per Story"; +"lng_stats_overview_mean_story_reactions_count" = "Reactions Per Story"; "lng_stats_overview_enabled_notifications" = "Enabled Notifications"; "lng_stats_overview_messages" = "Messages"; "lng_stats_overview_group_mean_view_count" = "Viewing Members"; diff --git a/Telegram/SourceFiles/api/api_statistics.cpp b/Telegram/SourceFiles/api/api_statistics.cpp index 1c0793b2d..14b2b56b2 100644 --- a/Telegram/SourceFiles/api/api_statistics.cpp +++ b/Telegram/SourceFiles/api/api_statistics.cpp @@ -93,6 +93,13 @@ constexpr auto kCheckRequestsTimer = 10 * crl::time(1000); .meanReactionCount = StatisticalValueFromTL( data.vreactions_per_post()), + .meanStoryViewCount = StatisticalValueFromTL( + data.vviews_per_story()), + .meanStoryShareCount = StatisticalValueFromTL( + data.vshares_per_story()), + .meanStoryReactionCount = StatisticalValueFromTL( + data.vreactions_per_story()), + .enabledNotificationsPercentage = unmuted, .memberCountGraph = StatisticalGraphFromTL( diff --git a/Telegram/SourceFiles/data/data_statistics.h b/Telegram/SourceFiles/data/data_statistics.h index 59bc72868..354ae1902 100644 --- a/Telegram/SourceFiles/data/data_statistics.h +++ b/Telegram/SourceFiles/data/data_statistics.h @@ -58,6 +58,9 @@ struct ChannelStatistics final { StatisticalValue meanViewCount; StatisticalValue meanShareCount; StatisticalValue meanReactionCount; + StatisticalValue meanStoryViewCount; + StatisticalValue meanStoryShareCount; + StatisticalValue meanStoryReactionCount; float64 enabledNotificationsPercentage = 0.; diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp index 62f77f478..99b1dbe1c 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp @@ -301,15 +301,18 @@ void AddHeader( void FillOverview( not_null content, - const Data::AnyStatistics &stats) { + const Data::AnyStatistics &stats, + bool isChannelStoryStats) { using Value = Data::StatisticalValue; const auto &channel = stats.channel; const auto &supergroup = stats.supergroup; - Ui::AddSkip(content, st::statisticsLayerOverviewMargins.top()); - AddHeader(content, tr::lng_stats_overview_title, stats); - Ui::AddSkip(content); + if (!isChannelStoryStats) { + Ui::AddSkip(content, st::statisticsLayerOverviewMargins.top()); + AddHeader(content, tr::lng_stats_overview_title, stats); + Ui::AddSkip(content); + } struct Second final { QColor color; @@ -318,7 +321,7 @@ void FillOverview( const auto parseSecond = [&](const Value &v) -> Second { const auto diff = v.value - v.previousValue; - if (!diff) { + if (!diff || !v.previousValue) { return {}; } constexpr auto kTooMuchDiff = int(1'000'000); @@ -385,12 +388,21 @@ void FillOverview( const auto isChannel = (!!channel); const auto &messageOrStory = stats.message ? stats.message : stats.story; const auto isMessage = (!!messageOrStory); - const auto topLeftLabel = isChannel + + const auto hasPostReactions = isChannel + && (channel.meanReactionCount.value + || channel.meanReactionCount.previousValue); + + const auto topLeftLabel = (isChannelStoryStats && isChannel) + ? addPrimary(channel.meanShareCount) + : isChannel ? addPrimary(channel.memberCount) : isMessage ? addPrimary({ .value = float64(messageOrStory.views) }) : addPrimary(supergroup.memberCount); - const auto topRightLabel = isChannel + const auto topRightLabel = (isChannelStoryStats && isChannel) + ? addPrimary(channel.meanStoryShareCount) + : isChannel ? Ui::CreateChild( container, QString("%1%").arg(0.01 @@ -399,17 +411,48 @@ void FillOverview( : isMessage ? addPrimary({ .value = float64(messageOrStory.publicForwards) }) : addPrimary(supergroup.messageCount); - const auto bottomLeftLabel = isChannel + const auto bottomLeftLabel = (isChannelStoryStats && isChannel) + ? addPrimary(hasPostReactions + ? channel.meanReactionCount + : channel.meanStoryReactionCount) + : isChannel ? addPrimary(channel.meanViewCount) : isMessage ? addPrimary({ .value = float64(messageOrStory.reactions) }) : addPrimary(supergroup.viewerCount); - const auto bottomRightLabel = isChannel - ? addPrimary(channel.meanShareCount) + const auto bottomRightLabel = (isChannelStoryStats && isChannel) + ? addPrimary(!hasPostReactions + ? Value{ .value = -1 } + : channel.meanStoryReactionCount) + : isChannel + ? addPrimary(channel.meanStoryViewCount) : isMessage ? addPrimary({ .value = float64(messageOrStory.privateForwards) }) : addPrimary(supergroup.senderCount); - if (const auto &s = channel) { + if (isChannelStoryStats && isChannel) { + addSub( + topLeftLabel, + channel.meanShareCount, + tr::lng_stats_overview_mean_share_count); + addSub( + topRightLabel, + channel.meanStoryShareCount, + tr::lng_stats_overview_mean_story_share_count); + addSub( + bottomLeftLabel, + hasPostReactions + ? channel.meanReactionCount + : channel.meanStoryReactionCount, + hasPostReactions + ? tr::lng_stats_overview_mean_reactions_count + : tr::lng_stats_overview_mean_story_reactions_count); + if (hasPostReactions) { + addSub( + bottomRightLabel, + channel.meanStoryReactionCount, + tr::lng_stats_overview_mean_story_reactions_count); + } + } else if (const auto &s = channel) { addSub( topLeftLabel, s.memberCount, @@ -424,8 +467,8 @@ void FillOverview( tr::lng_stats_overview_mean_view_count); addSub( bottomRightLabel, - s.meanShareCount, - tr::lng_stats_overview_mean_share_count); + s.meanStoryViewCount, + tr::lng_stats_overview_mean_story_view_count); } else if (const auto &s = supergroup) { addSub( topLeftLabel, @@ -636,7 +679,10 @@ void InnerWidget::fill() { Ui::AddDivider(inner); } } - FillOverview(inner, _state.stats); + FillOverview(inner, _state.stats, false); + if (_state.stats.channel) { + FillOverview(inner, _state.stats, true); + } FillStatistic(inner, descriptor, _state.stats); const auto &channel = _state.stats.channel; const auto &supergroup = _state.stats.supergroup;