Add recent story interactions in chat statistics.

This commit is contained in:
levlam 2023-11-20 19:46:49 +03:00
parent 72bf7f0cd7
commit c1352603d5
2 changed files with 57 additions and 18 deletions

View File

@ -5894,11 +5894,21 @@ statisticalGraphAsync token:string = StatisticalGraph;
statisticalGraphError error_message:string = StatisticalGraph; statisticalGraphError error_message:string = StatisticalGraph;
//@description Contains statistics about interactions with a message //@class ChatStatisticsObjectType @description Describes type of an object, for which statistics is provided
//@message_id Message identifier
//@view_count Number of times the message was viewed //@description Describes a message sent in the chat @message_id Message identifier
//@forward_count Number of times the message was forwarded chatStatisticsObjectTypeMessage message_id:int53 = ChatStatisticsObjectType;
chatStatisticsMessageInteractionInfo message_id:int53 view_count:int32 forward_count:int32 = ChatStatisticsMessageInteractionInfo;
//@description Describes a story sent by the chat @story_id Story identifier
chatStatisticsObjectTypeStory story_id:int32 = ChatStatisticsObjectType;
//@description Contains statistics about interactions with a message sent in the chat or a story sent by the chat
//@object_type Type of the object
//@view_count Number of times the object was viewed
//@forward_count Number of times the object was forwarded
//@reaction_count Number of times reactions were added to the object
chatStatisticsInteractionInfo object_type:ChatStatisticsObjectType view_count:int32 forward_count:int32 reaction_count:int32 = ChatStatisticsInteractionInfo;
//@description Contains statistics about messages sent by a user //@description Contains statistics about messages sent by a user
//@user_id User identifier //@user_id User identifier
@ -5962,8 +5972,8 @@ chatStatisticsSupergroup period:dateRange member_count:statisticalValue message_
//@story_interaction_graph A graph containing number of story views and shares //@story_interaction_graph A graph containing number of story views and shares
//@story_reaction_graph A graph containing number of reactions on stories //@story_reaction_graph A graph containing number of reactions on stories
//@instant_view_interaction_graph A graph containing number of views of associated with the chat instant views //@instant_view_interaction_graph A graph containing number of views of associated with the chat instant views
//@recent_message_interactions Detailed statistics about number of views and shares of recently sent messages //@recent_interactions Detailed statistics about number of views and shares of recently sent messages and stories
chatStatisticsChannel period:dateRange member_count:statisticalValue mean_message_view_count:statisticalValue mean_message_share_count:statisticalValue mean_message_reaction_count:statisticalValue mean_story_view_count:statisticalValue mean_story_share_count:statisticalValue mean_story_reaction_count:statisticalValue enabled_notifications_percentage:double member_count_graph:StatisticalGraph join_graph:StatisticalGraph mute_graph:StatisticalGraph view_count_by_hour_graph:StatisticalGraph view_count_by_source_graph:StatisticalGraph join_by_source_graph:StatisticalGraph language_graph:StatisticalGraph message_interaction_graph:StatisticalGraph message_reaction_graph:StatisticalGraph story_interaction_graph:StatisticalGraph story_reaction_graph:StatisticalGraph instant_view_interaction_graph:StatisticalGraph recent_message_interactions:vector<chatStatisticsMessageInteractionInfo> = ChatStatistics; chatStatisticsChannel period:dateRange member_count:statisticalValue mean_message_view_count:statisticalValue mean_message_share_count:statisticalValue mean_message_reaction_count:statisticalValue mean_story_view_count:statisticalValue mean_story_share_count:statisticalValue mean_story_reaction_count:statisticalValue enabled_notifications_percentage:double member_count_graph:StatisticalGraph join_graph:StatisticalGraph mute_graph:StatisticalGraph view_count_by_hour_graph:StatisticalGraph view_count_by_source_graph:StatisticalGraph join_by_source_graph:StatisticalGraph language_graph:StatisticalGraph message_interaction_graph:StatisticalGraph message_reaction_graph:StatisticalGraph story_interaction_graph:StatisticalGraph story_reaction_graph:StatisticalGraph instant_view_interaction_graph:StatisticalGraph recent_interactions:vector<chatStatisticsInteractionInfo> = ChatStatistics;
//@description A detailed statistics about a message //@description A detailed statistics about a message

View File

@ -131,12 +131,31 @@ static td_api::object_ptr<td_api::chatStatisticsSupergroup> convert_megagroup_st
static td_api::object_ptr<td_api::chatStatisticsChannel> convert_broadcast_stats( static td_api::object_ptr<td_api::chatStatisticsChannel> convert_broadcast_stats(
telegram_api::object_ptr<telegram_api::stats_broadcastStats> obj) { telegram_api::object_ptr<telegram_api::stats_broadcastStats> obj) {
CHECK(obj != nullptr); CHECK(obj != nullptr);
/* auto recent_interactions = transform(
auto recent_message_interactions = transform(std::move(obj->recent_message_interactions_), [](auto &&interaction) { std::move(obj->recent_posts_interactions_),
return td_api::make_object<td_api::chatStatisticsMessageInteractionInfo>( [](telegram_api::object_ptr<telegram_api::PostInteractionCounters> &&interaction_ptr)
MessageId(ServerMessageId(interaction->msg_id_)).get(), interaction->views_, interaction->forwards_); -> td_api::object_ptr<td_api::chatStatisticsInteractionInfo> {
}); switch (interaction_ptr->get_id()) {
*/ case telegram_api::postInteractionCountersMessage::ID: {
auto interaction =
telegram_api::move_object_as<telegram_api::postInteractionCountersMessage>(interaction_ptr);
return td_api::make_object<td_api::chatStatisticsInteractionInfo>(
td_api::make_object<td_api::chatStatisticsObjectTypeMessage>(
MessageId(ServerMessageId(interaction->msg_id_)).get()),
interaction->views_, interaction->forwards_, interaction->reactions_);
}
case telegram_api::postInteractionCountersStory::ID: {
auto interaction =
telegram_api::move_object_as<telegram_api::postInteractionCountersStory>(interaction_ptr);
return td_api::make_object<td_api::chatStatisticsInteractionInfo>(
td_api::make_object<td_api::chatStatisticsObjectTypeStory>(StoryId(interaction->story_id_).get()),
interaction->views_, interaction->forwards_, interaction->reactions_);
}
default:
UNREACHABLE();
return nullptr;
}
});
return td_api::make_object<td_api::chatStatisticsChannel>( return td_api::make_object<td_api::chatStatisticsChannel>(
convert_date_range(obj->period_), convert_stats_absolute_value(obj->followers_), convert_date_range(obj->period_), convert_stats_absolute_value(obj->followers_),
convert_stats_absolute_value(obj->views_per_post_), convert_stats_absolute_value(obj->shares_per_post_), convert_stats_absolute_value(obj->views_per_post_), convert_stats_absolute_value(obj->shares_per_post_),
@ -151,7 +170,7 @@ static td_api::object_ptr<td_api::chatStatisticsChannel> convert_broadcast_stats
convert_stats_graph(std::move(obj->reactions_by_emotion_graph_)), convert_stats_graph(std::move(obj->reactions_by_emotion_graph_)),
convert_stats_graph(std::move(obj->story_interactions_graph_)), convert_stats_graph(std::move(obj->story_interactions_graph_)),
convert_stats_graph(std::move(obj->story_reactions_by_emotion_graph_)), convert_stats_graph(std::move(obj->story_reactions_by_emotion_graph_)),
convert_stats_graph(std::move(obj->iv_interactions_graph_)), Auto()); convert_stats_graph(std::move(obj->iv_interactions_graph_)), std::move(recent_interactions));
} }
class GetMegagroupStatsQuery final : public Td::ResultHandler { class GetMegagroupStatsQuery final : public Td::ResultHandler {
@ -222,10 +241,20 @@ class GetBroadcastStatsQuery final : public Td::ResultHandler {
} }
auto result = convert_broadcast_stats(result_ptr.move_as_ok()); auto result = convert_broadcast_stats(result_ptr.move_as_ok());
for (auto &info : result->recent_message_interactions_) { for (auto &info : result->recent_interactions_) {
td_->messages_manager_->on_update_message_interaction_info({DialogId(channel_id_), MessageId(info->message_id_)}, switch (info->object_type_->get_id()) {
info->view_count_, info->forward_count_, false, case td_api::chatStatisticsObjectTypeMessage::ID: {
nullptr); MessageId message_id(
static_cast<const td_api::chatStatisticsObjectTypeMessage *>(info->object_type_.get())->message_id_);
td_->messages_manager_->on_update_message_interaction_info(
{DialogId(channel_id_), message_id}, info->view_count_, info->forward_count_, false, nullptr);
break;
}
case td_api::chatStatisticsObjectTypeStory::ID:
break;
default:
UNREACHABLE();
}
} }
promise_.set_value(std::move(result)); promise_.set_value(std::move(result));
} }