From 3fa6335b24ff2874b66e3581d8e6cd470a6fc87f Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 29 Sep 2023 01:47:51 +0300 Subject: [PATCH] Added API support to request statistical graph for single message. --- Telegram/SourceFiles/api/api_statistics.cpp | 28 ++++++++++++++++++++- Telegram/SourceFiles/api/api_statistics.h | 6 ++++- 2 files changed, 32 insertions(+), 2 deletions(-) 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;