Added new charts to channel and message statistics.

This commit is contained in:
23rd 2023-11-17 00:44:59 +03:00 committed by John Preston
parent 44f6280d0a
commit 173a5046e8
4 changed files with 45 additions and 5 deletions

View File

@ -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";

View File

@ -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<void(Data::MessageStatistics)> 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<void(Data::MessageStatistics)> done) {
};
const auto requestPrivateForwards = [=](
const Data::StatisticalGraph &messageGraph) {
const Data::StatisticalGraph &messageGraph,
const Data::StatisticalGraph &reactionsGraph) {
api().request(MTPchannels_GetMessages(
channel()->inputChannel,
MTP_vector<MTPInputMessage>(
@ -488,9 +500,12 @@ void MessageStatistics::request(Fn<void(Data::MessageStatistics)> 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<void(Data::MessageStatistics)> 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();
}

View File

@ -67,6 +67,9 @@ struct ChannelStatistics final {
StatisticalGraph languageGraph;
StatisticalGraph messageInteractionGraph;
StatisticalGraph instantViewInteractionGraph;
StatisticalGraph reactionsByEmotionGraph;
StatisticalGraph storyInteractionsGraph;
StatisticalGraph storyReactionsByEmotionGraph;
std::vector<StatisticsMessageInteractionInfo> 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;

View File

@ -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);
}
}