Added API support to request statistical graph for single message.

This commit is contained in:
23rd 2023-09-29 01:47:51 +03:00 committed by John Preston
parent 23868bf9cc
commit 3fa6335b24
2 changed files with 32 additions and 2 deletions

View file

@ -225,7 +225,7 @@ rpl::producer<rpl::no_value, QString> Statistics::request(
};
}
rpl::producer<Data::StatisticalGraph, QString> Statistics::requestZoom(
Statistics::GraphResult Statistics::requestZoom(
not_null<PeerData*> peer,
const QString &token,
float64 x) {
@ -253,6 +253,32 @@ rpl::producer<Data::StatisticalGraph, QString> Statistics::requestZoom(
};
}
Statistics::GraphResult Statistics::requestMessage(
not_null<PeerData*> peer,
MsgId msgId) {
return [=](auto consumer) {
auto lifetime = rpl::lifetime();
const auto channel = peer->asChannel();
if (!channel) {
return lifetime;
}
_api.request(MTPstats_GetMessageStats(
MTP_flags(MTPstats_GetMessageStats::Flags(0)),
channel->inputChannel,
MTP_int(msgId.bare)
)).done([=](const MTPstats_MessageStats &result) {
consumer.put_next(
StatisticalGraphFromTL(result.data().vviews_graph()));
consumer.put_done();
}).fail([=](const MTP::Error &error) {
consumer.put_error_copy(error.type());
}).send();
return lifetime;
};
}
Data::ChannelStatistics Statistics::channelStats() const {
return _channelStats;
}

View file

@ -21,10 +21,14 @@ public:
[[nodiscard]] rpl::producer<rpl::no_value, QString> request(
not_null<PeerData*> peer);
[[nodiscard]] rpl::producer<Data::StatisticalGraph, QString> requestZoom(
using GraphResult = rpl::producer<Data::StatisticalGraph, QString>;
[[nodiscard]] GraphResult requestZoom(
not_null<PeerData*> peer,
const QString &token,
float64 x);
[[nodiscard]] GraphResult requestMessage(
not_null<PeerData*> peer,
MsgId msgId);
[[nodiscard]] Data::ChannelStatistics channelStats() const;
[[nodiscard]] Data::SupergroupStatistics supergroupStats() const;