Added API support to resolve story statistics.

This commit is contained in:
23rd 2023-11-17 05:57:50 +03:00 committed by John Preston
parent 34d0dac351
commit 1056a5cc8e
3 changed files with 69 additions and 12 deletions

View file

@ -437,6 +437,14 @@ MessageStatistics::MessageStatistics(
, _fullId(fullId) { , _fullId(fullId) {
} }
MessageStatistics::MessageStatistics(
not_null<ChannelData*> channel,
FullStoryId storyId)
: StatisticsRequestSender(channel)
, _publicForwards(channel, {})
, _storyId(storyId) {
}
Data::PublicForwardsSlice MessageStatistics::firstSlice() const { Data::PublicForwardsSlice MessageStatistics::firstSlice() const {
return _firstSlice; return _firstSlice;
} }
@ -518,18 +526,60 @@ void MessageStatistics::request(Fn<void(Data::MessageStatistics)> done) {
}).send(); }).send();
}; };
makeRequest(MTPstats_GetMessageStats( const auto requestStoryPrivateForwards = [=](
MTP_flags(MTPstats_GetMessageStats::Flags(0)), const Data::StatisticalGraph &messageGraph,
channel()->inputChannel, const Data::StatisticalGraph &reactionsGraph) {
MTP_int(_fullId.msg.bare) api().request(MTPstories_GetStoriesByID(
)).done([=](const MTPstats_MessageStats &result) { channel()->input,
const auto &data = result.data(); MTP_vector<MTPint>(1, MTP_int(_storyId.story)))
requestPrivateForwards( ).done([=](const MTPstories_Stories &result) {
StatisticalGraphFromTL(data.vviews_graph()), const auto &storyItem = result.data().vstories().v.front();
StatisticalGraphFromTL(data.vreactions_by_emotion_graph())); storyItem.match([&](const MTPDstoryItem &data) {
}).fail([=](const MTP::Error &error) { if (!data.vviews()) {
requestPrivateForwards({}, {}); return;
}).send(); }
const auto &tlViews = data.vviews()->data();
done({
.messageInteractionGraph = messageGraph,
.reactionsByEmotionGraph = reactionsGraph,
.publicForwards = -1,
.privateForwards = tlViews.vforwards_count().value_or(0),
.views = tlViews.vviews_count().v,
.reactions = tlViews.vreactions_count().value_or(0),
});
}, [](const auto &) {
});
}).fail([=](const MTP::Error &error) {
}).send();
};
if (_storyId) {
makeRequest(MTPstats_GetStoryStats(
MTP_flags(MTPstats_GetStoryStats::Flags(0)),
channel()->input,
MTP_int(_storyId.story)
)).done([=](const MTPstats_StoryStats &result) {
const auto &data = result.data();
requestStoryPrivateForwards(
StatisticalGraphFromTL(data.vviews_graph()),
StatisticalGraphFromTL(data.vreactions_by_emotion_graph()));
}).fail([=](const MTP::Error &error) {
requestStoryPrivateForwards({}, {});
}).send();
} else {
makeRequest(MTPstats_GetMessageStats(
MTP_flags(MTPstats_GetMessageStats::Flags(0)),
channel()->inputChannel,
MTP_int(_fullId.msg.bare)
)).done([=](const MTPstats_MessageStats &result) {
const auto &data = result.data();
requestPrivateForwards(
StatisticalGraphFromTL(data.vviews_graph()),
StatisticalGraphFromTL(data.vreactions_by_emotion_graph()));
}).fail([=](const MTP::Error &error) {
requestPrivateForwards({}, {});
}).send();
}
} }
Boosts::Boosts(not_null<PeerData*> peer) Boosts::Boosts(not_null<PeerData*> peer)

View file

@ -86,6 +86,9 @@ public:
explicit MessageStatistics( explicit MessageStatistics(
not_null<ChannelData*> channel, not_null<ChannelData*> channel,
FullMsgId fullId); FullMsgId fullId);
explicit MessageStatistics(
not_null<ChannelData*> channel,
FullStoryId storyId);
void request(Fn<void(Data::MessageStatistics)> done); void request(Fn<void(Data::MessageStatistics)> done);
@ -94,6 +97,7 @@ public:
private: private:
PublicForwards _publicForwards; PublicForwards _publicForwards;
const FullMsgId _fullId; const FullMsgId _fullId;
const FullStoryId _storyId;
Data::PublicForwardsSlice _firstSlice; Data::PublicForwardsSlice _firstSlice;

View file

@ -118,11 +118,14 @@ struct MessageStatistics final {
int views = 0; int views = 0;
int reactions = 0; int reactions = 0;
}; };
// At the moment, the structures are identical.
using StoryStatistics = MessageStatistics;
struct AnyStatistics final { struct AnyStatistics final {
Data::ChannelStatistics channel; Data::ChannelStatistics channel;
Data::SupergroupStatistics supergroup; Data::SupergroupStatistics supergroup;
Data::MessageStatistics message; Data::MessageStatistics message;
Data::StoryStatistics story;
}; };
struct PublicForwardsSlice final { struct PublicForwardsSlice final {