diff --git a/Telegram/SourceFiles/api/api_statistics.cpp b/Telegram/SourceFiles/api/api_statistics.cpp index 234fb4ff8..aeddce54a 100644 --- a/Telegram/SourceFiles/api/api_statistics.cpp +++ b/Telegram/SourceFiles/api/api_statistics.cpp @@ -225,7 +225,7 @@ rpl::producer Statistics::request( }; } -rpl::producer Statistics::requestZoom( +Statistics::GraphResult Statistics::requestZoom( not_null peer, const QString &token, float64 x) { @@ -253,6 +253,32 @@ rpl::producer Statistics::requestZoom( }; } +Statistics::GraphResult Statistics::requestMessage( + not_null 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; } diff --git a/Telegram/SourceFiles/api/api_statistics.h b/Telegram/SourceFiles/api/api_statistics.h index c4b795835..76df8bc49 100644 --- a/Telegram/SourceFiles/api/api_statistics.h +++ b/Telegram/SourceFiles/api/api_statistics.h @@ -21,10 +21,14 @@ public: [[nodiscard]] rpl::producer request( not_null peer); - [[nodiscard]] rpl::producer requestZoom( + using GraphResult = rpl::producer; + [[nodiscard]] GraphResult requestZoom( not_null peer, const QString &token, float64 x); + [[nodiscard]] GraphResult requestMessage( + not_null peer, + MsgId msgId); [[nodiscard]] Data::ChannelStatistics channelStats() const; [[nodiscard]] Data::SupergroupStatistics supergroupStats() const;