From eb0ab9609f7d2dd8dcd547cf3ef5bcd11a482f23 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 27 Jul 2023 07:03:53 +0300 Subject: [PATCH] Added API support for request of async zoom single chart. --- Telegram/SourceFiles/api/api_statistics.cpp | 36 ++++++++++++++++++++- Telegram/SourceFiles/api/api_statistics.h | 4 +++ Telegram/SourceFiles/data/data_statistics.h | 1 + 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/api/api_statistics.cpp b/Telegram/SourceFiles/api/api_statistics.cpp index 42c0169305..69c7145f58 100644 --- a/Telegram/SourceFiles/api/api_statistics.cpp +++ b/Telegram/SourceFiles/api/api_statistics.cpp @@ -20,11 +20,17 @@ namespace { const MTPStatsGraph &tl) { return tl.match([&](const MTPDstatsGraph &d) { using namespace Statistic; + const auto zoomToken = d.vzoom_token().has_value() + ? qs(*d.vzoom_token()).toUtf8() + : QByteArray(); return Data::StatisticalGraph{ StatisticalChartFromJSON(qs(d.vjson().data().vdata()).toUtf8()), + zoomToken, }; }, [&](const MTPDstatsGraphAsync &data) { - return Data::StatisticalGraph{ Data::StatisticalChart() }; + return Data::StatisticalGraph{ + .zoomToken = qs(data.vtoken()).toUtf8(), + }; }, [&](const MTPDstatsGraphError &data) { return Data::StatisticalGraph{ Data::StatisticalChart() }; }); @@ -135,6 +141,34 @@ rpl::producer Statistics::request( }; } +rpl::producer Statistics::requestZoom( + not_null peer, + const QString &token, + float64 x) { + return [=](auto consumer) { + auto lifetime = rpl::lifetime(); + const auto channel = peer->asChannel(); + if (!channel) { + return lifetime; + } + + _api.request(MTPstats_LoadAsyncGraph( + MTP_flags(x + ? MTPstats_LoadAsyncGraph::Flag::f_x + : MTPstats_LoadAsyncGraph::Flag(0)), + MTP_string(token), + MTP_long(x) + )).done([=](const MTPStatsGraph &result) { + consumer.put_next(StatisticalGraphFromTL(result)); + 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 6591976e71..772e79078e 100644 --- a/Telegram/SourceFiles/api/api_statistics.h +++ b/Telegram/SourceFiles/api/api_statistics.h @@ -21,6 +21,10 @@ public: [[nodiscard]] rpl::producer request( not_null peer); + [[nodiscard]] rpl::producer requestZoom( + not_null peer, + const QString &token, + float64 x); [[nodiscard]] Data::ChannelStatistics channelStats() const; diff --git a/Telegram/SourceFiles/data/data_statistics.h b/Telegram/SourceFiles/data/data_statistics.h index d411d87046..53f0607be5 100644 --- a/Telegram/SourceFiles/data/data_statistics.h +++ b/Telegram/SourceFiles/data/data_statistics.h @@ -84,6 +84,7 @@ struct StatisticalChart { struct StatisticalGraph final { StatisticalChart chart; + QString zoomToken; }; struct StatisticalValue final {