From 5b67f4ac9bd4eeb5007730b6b10984ec98da3287 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 28 Sep 2023 23:41:09 +0300 Subject: [PATCH] Added overview info to statistic of supergroup. --- Telegram/Resources/langs/lang.strings | 3 + .../SourceFiles/statistics/statistics_box.cpp | 117 ++++++++++++------ 2 files changed, 82 insertions(+), 38 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index b1c1d5301e..e8650ebf6d 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -4073,6 +4073,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_stats_overview_mean_view_count" = "Views Per Post"; "lng_stats_overview_mean_share_count" = "Shared Per Post"; "lng_stats_overview_enabled_notifications" = "Enabled Notifications"; +"lng_stats_overview_messages" = "Messages"; +"lng_stats_overview_group_mean_view_count" = "Viewing Members"; +"lng_stats_overview_group_mean_post_count" = "Posting Members"; "lng_stats_loading" = "Loading stats..."; "lng_stats_loading_subtext" = "Please wait a few moments while we generate your stats."; diff --git a/Telegram/SourceFiles/statistics/statistics_box.cpp b/Telegram/SourceFiles/statistics/statistics_box.cpp index a4811c2478..73640e303a 100644 --- a/Telegram/SourceFiles/statistics/statistics_box.cpp +++ b/Telegram/SourceFiles/statistics/statistics_box.cpp @@ -277,20 +277,24 @@ void FillLoading( Settings::AddSkip(content, st::settingsBlockedListIconPadding.top()); } -void FillChannelOverview( +void FillOverview( not_null box, const Descriptor &descriptor, - const Data::ChannelStatistics &stats) { + const Data::ChannelStatistics &channel, + const Data::SupergroupStatistics &supergroup) { using Value = Data::StatisticalValue; + const auto startDate = channel ? channel.startDate : supergroup.startDate; + const auto endDate = channel ? channel.endDate : supergroup.endDate; + Settings::AddSkip(box->verticalLayout()); { const auto header = box->addRow(object_ptr(box)); header->resize(header->width(), st::statisticsChartHeaderHeight); header->setTitle(tr::lng_stats_overview_title(tr::now)); const auto formatter = u"MMM d"_q; - const auto from = QDateTime::fromSecsSinceEpoch(stats.startDate); - const auto to = QDateTime::fromSecsSinceEpoch(stats.endDate); + const auto from = QDateTime::fromSecsSinceEpoch(startDate); + const auto to = QDateTime::fromSecsSinceEpoch(endDate); header->setRightInfo(QLocale().toString(from.date(), formatter) + ' ' + QChar(8212) @@ -352,42 +356,79 @@ void FillChannelOverview( }, primary->lifetime()); }; - const auto memberCount = addPrimary(stats.memberCount); - const auto enabledNotifications = Ui::CreateChild( - container, - QString("%1%").arg( - std::round(stats.enabledNotificationsPercentage * 100.) / 100.), - st::statisticsOverviewValue); - const auto meanViewCount = addPrimary(stats.meanViewCount); - const auto meanShareCount = addPrimary(stats.meanShareCount); + auto height = 0; + if (const auto s = channel; s) { + const auto memberCount = addPrimary(s.memberCount); + const auto enabledNotifications = Ui::CreateChild( + container, + QString("%1%").arg( + std::round(s.enabledNotificationsPercentage * 100.) / 100.), + st::statisticsOverviewValue); + const auto meanViewCount = addPrimary(s.meanViewCount); + const auto meanShareCount = addPrimary(s.meanShareCount); - addSub( - memberCount, - stats.memberCount, - tr::lng_stats_overview_member_count); - addSub( - enabledNotifications, - {}, - tr::lng_stats_overview_enabled_notifications); - addSub( - meanViewCount, - stats.meanViewCount, - tr::lng_stats_overview_mean_view_count); - addSub( - meanShareCount, - stats.meanShareCount, - tr::lng_stats_overview_mean_share_count); + addSub( + memberCount, + s.memberCount, + tr::lng_stats_overview_member_count); + addSub( + enabledNotifications, + {}, + tr::lng_stats_overview_enabled_notifications); + addSub( + meanViewCount, + s.meanViewCount, + tr::lng_stats_overview_mean_view_count); + addSub( + meanShareCount, + s.meanShareCount, + tr::lng_stats_overview_mean_share_count); - container->sizeValue( - ) | rpl::start_with_next([=](const QSize &s) { - const auto halfWidth = s.width() / 2; - enabledNotifications->moveToLeft(halfWidth, 0); - meanViewCount->moveToLeft(0, meanViewCount->height() * 3); - meanShareCount->moveToLeft(halfWidth, meanViewCount->y()); - }, container->lifetime()); + container->sizeValue( + ) | rpl::start_with_next([=](const QSize &s) { + const auto halfWidth = s.width() / 2; + enabledNotifications->moveToLeft(halfWidth, 0); + meanViewCount->moveToLeft(0, meanViewCount->height() * 3); + meanShareCount->moveToLeft(halfWidth, meanViewCount->y()); + }, container->lifetime()); + + height = memberCount->height() * 5; + } else if (const auto s = supergroup; s) { + const auto memberCount = addPrimary(s.memberCount); + const auto messageCount = addPrimary(s.messageCount); + const auto viewerCount = addPrimary(s.viewerCount); + const auto senderCount = addPrimary(s.senderCount); + + addSub( + memberCount, + s.memberCount, + tr::lng_manage_peer_members); + addSub( + messageCount, + s.messageCount, + tr::lng_stats_overview_messages); + addSub( + viewerCount, + s.viewerCount, + tr::lng_stats_overview_group_mean_view_count); + addSub( + senderCount, + s.senderCount, + tr::lng_stats_overview_group_mean_post_count); + + container->sizeValue( + ) | rpl::start_with_next([=](const QSize &s) { + const auto halfWidth = s.width() / 2; + messageCount->moveToLeft(halfWidth, 0); + viewerCount->moveToLeft(0, memberCount->height() * 3); + senderCount->moveToLeft(halfWidth, viewerCount->y()); + }, container->lifetime()); + + height = memberCount->height() * 5; + } container->showChildren(); - container->resize(container->width(), meanViewCount->height() * 5); + container->resize(container->width(), height); } } // namespace @@ -409,10 +450,10 @@ void StatisticsBox(not_null box, not_null peer) { descriptor.peer ) | rpl::start_with_done([=] { if (const auto stats = descriptor.api->supergroupStats(); stats) { - // FillSupergroupOverview(box, descriptor, stats); + FillOverview(box, descriptor, {}, stats); FillSupergroupStatistic(box, descriptor, stats); } else if (const auto stats = descriptor.api->channelStats(); stats) { - FillChannelOverview(box, descriptor, stats); + FillOverview(box, descriptor, stats, {}); FillChannelStatistic(box, descriptor, stats); } else { return;