mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Added API support to resolve story statistics.
This commit is contained in:
parent
34d0dac351
commit
1056a5cc8e
3 changed files with 69 additions and 12 deletions
|
@ -437,6 +437,14 @@ MessageStatistics::MessageStatistics(
|
|||
, _fullId(fullId) {
|
||||
}
|
||||
|
||||
MessageStatistics::MessageStatistics(
|
||||
not_null<ChannelData*> channel,
|
||||
FullStoryId storyId)
|
||||
: StatisticsRequestSender(channel)
|
||||
, _publicForwards(channel, {})
|
||||
, _storyId(storyId) {
|
||||
}
|
||||
|
||||
Data::PublicForwardsSlice MessageStatistics::firstSlice() const {
|
||||
return _firstSlice;
|
||||
}
|
||||
|
@ -518,18 +526,60 @@ void MessageStatistics::request(Fn<void(Data::MessageStatistics)> done) {
|
|||
}).send();
|
||||
};
|
||||
|
||||
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();
|
||||
const auto requestStoryPrivateForwards = [=](
|
||||
const Data::StatisticalGraph &messageGraph,
|
||||
const Data::StatisticalGraph &reactionsGraph) {
|
||||
api().request(MTPstories_GetStoriesByID(
|
||||
channel()->input,
|
||||
MTP_vector<MTPint>(1, MTP_int(_storyId.story)))
|
||||
).done([=](const MTPstories_Stories &result) {
|
||||
const auto &storyItem = result.data().vstories().v.front();
|
||||
storyItem.match([&](const MTPDstoryItem &data) {
|
||||
if (!data.vviews()) {
|
||||
return;
|
||||
}
|
||||
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)
|
||||
|
|
|
@ -86,6 +86,9 @@ public:
|
|||
explicit MessageStatistics(
|
||||
not_null<ChannelData*> channel,
|
||||
FullMsgId fullId);
|
||||
explicit MessageStatistics(
|
||||
not_null<ChannelData*> channel,
|
||||
FullStoryId storyId);
|
||||
|
||||
void request(Fn<void(Data::MessageStatistics)> done);
|
||||
|
||||
|
@ -94,6 +97,7 @@ public:
|
|||
private:
|
||||
PublicForwards _publicForwards;
|
||||
const FullMsgId _fullId;
|
||||
const FullStoryId _storyId;
|
||||
|
||||
Data::PublicForwardsSlice _firstSlice;
|
||||
|
||||
|
|
|
@ -118,11 +118,14 @@ struct MessageStatistics final {
|
|||
int views = 0;
|
||||
int reactions = 0;
|
||||
};
|
||||
// At the moment, the structures are identical.
|
||||
using StoryStatistics = MessageStatistics;
|
||||
|
||||
struct AnyStatistics final {
|
||||
Data::ChannelStatistics channel;
|
||||
Data::SupergroupStatistics supergroup;
|
||||
Data::MessageStatistics message;
|
||||
Data::StoryStatistics story;
|
||||
};
|
||||
|
||||
struct PublicForwardsSlice final {
|
||||
|
|
Loading…
Add table
Reference in a new issue