2023-04-26 20:05:12 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2023-11-11 17:20:09 +00:00
|
|
|
#include "base/timer.h"
|
2023-10-11 21:09:43 +00:00
|
|
|
#include "data/data_boosts.h"
|
2023-04-26 20:58:03 +00:00
|
|
|
#include "data/data_statistics.h"
|
2023-04-26 20:05:12 +00:00
|
|
|
#include "mtproto/sender.h"
|
|
|
|
|
2023-10-09 02:09:23 +00:00
|
|
|
class ChannelData;
|
2023-04-26 20:05:12 +00:00
|
|
|
class PeerData;
|
|
|
|
|
|
|
|
namespace Api {
|
|
|
|
|
2023-11-11 17:20:09 +00:00
|
|
|
class StatisticsRequestSender {
|
|
|
|
protected:
|
|
|
|
explicit StatisticsRequestSender(not_null<ChannelData*> channel);
|
|
|
|
~StatisticsRequestSender();
|
|
|
|
|
|
|
|
template <
|
|
|
|
typename Request,
|
|
|
|
typename = std::enable_if_t<!std::is_reference_v<Request>>,
|
|
|
|
typename = typename Request::Unboxed>
|
|
|
|
[[nodiscard]] auto makeRequest(Request &&request);
|
|
|
|
|
|
|
|
[[nodiscard]] MTP::Sender &api() {
|
|
|
|
return _api;
|
|
|
|
}
|
|
|
|
[[nodiscard]] not_null<ChannelData*> channel() {
|
|
|
|
return _channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void checkRequests();
|
|
|
|
|
|
|
|
const not_null<ChannelData*> _channel;
|
|
|
|
MTP::Sender _api;
|
|
|
|
base::Timer _timer;
|
|
|
|
base::flat_map<MTP::DcId, base::flat_set<mtpRequestId>> _requests;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Statistics final : public StatisticsRequestSender {
|
2023-04-26 20:05:12 +00:00
|
|
|
public:
|
2023-11-11 11:58:44 +00:00
|
|
|
explicit Statistics(not_null<ChannelData*> channel);
|
2023-04-26 20:05:12 +00:00
|
|
|
|
2023-11-11 11:58:44 +00:00
|
|
|
[[nodiscard]] rpl::producer<rpl::no_value, QString> request();
|
2023-09-28 22:47:51 +00:00
|
|
|
using GraphResult = rpl::producer<Data::StatisticalGraph, QString>;
|
|
|
|
[[nodiscard]] GraphResult requestZoom(
|
2023-07-27 04:03:53 +00:00
|
|
|
const QString &token,
|
|
|
|
float64 x);
|
2023-04-26 20:58:03 +00:00
|
|
|
|
|
|
|
[[nodiscard]] Data::ChannelStatistics channelStats() const;
|
2023-09-28 20:20:07 +00:00
|
|
|
[[nodiscard]] Data::SupergroupStatistics supergroupStats() const;
|
2023-04-26 20:05:12 +00:00
|
|
|
|
|
|
|
private:
|
2023-04-26 20:58:03 +00:00
|
|
|
Data::ChannelStatistics _channelStats;
|
2023-09-28 20:20:07 +00:00
|
|
|
Data::SupergroupStatistics _supergroupStats;
|
2023-04-26 20:05:12 +00:00
|
|
|
|
2023-10-11 04:36:05 +00:00
|
|
|
std::deque<Fn<void()>> _zoomDeque;
|
|
|
|
|
2023-04-26 20:05:12 +00:00
|
|
|
};
|
|
|
|
|
2023-11-11 17:20:09 +00:00
|
|
|
class PublicForwards final : public StatisticsRequestSender {
|
2023-10-09 02:09:23 +00:00
|
|
|
public:
|
2023-11-28 02:30:16 +00:00
|
|
|
PublicForwards(
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
Data::RecentPostId fullId);
|
2023-10-09 02:09:23 +00:00
|
|
|
|
2023-10-11 02:10:09 +00:00
|
|
|
void request(
|
|
|
|
const Data::PublicForwardsSlice::OffsetToken &token,
|
|
|
|
Fn<void(Data::PublicForwardsSlice)> done);
|
2023-10-09 02:09:23 +00:00
|
|
|
|
|
|
|
private:
|
2023-11-28 02:30:16 +00:00
|
|
|
const Data::RecentPostId _fullId;
|
2023-10-09 02:09:23 +00:00
|
|
|
mtpRequestId _requestId = 0;
|
|
|
|
int _lastTotal = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2023-11-11 17:20:09 +00:00
|
|
|
class MessageStatistics final : public StatisticsRequestSender {
|
2023-10-09 14:10:43 +00:00
|
|
|
public:
|
|
|
|
explicit MessageStatistics(
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
FullMsgId fullId);
|
2023-11-17 02:57:50 +00:00
|
|
|
explicit MessageStatistics(
|
|
|
|
not_null<ChannelData*> channel,
|
|
|
|
FullStoryId storyId);
|
2023-10-09 14:10:43 +00:00
|
|
|
|
|
|
|
void request(Fn<void(Data::MessageStatistics)> done);
|
|
|
|
|
2023-10-11 02:10:09 +00:00
|
|
|
[[nodiscard]] Data::PublicForwardsSlice firstSlice() const;
|
2023-10-09 14:10:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
PublicForwards _publicForwards;
|
|
|
|
const FullMsgId _fullId;
|
2023-11-17 02:57:50 +00:00
|
|
|
const FullStoryId _storyId;
|
2023-10-09 14:10:43 +00:00
|
|
|
|
2023-10-11 02:10:09 +00:00
|
|
|
Data::PublicForwardsSlice _firstSlice;
|
2023-10-09 14:10:43 +00:00
|
|
|
|
|
|
|
mtpRequestId _requestId = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2023-10-11 21:09:43 +00:00
|
|
|
class Boosts final {
|
|
|
|
public:
|
|
|
|
explicit Boosts(not_null<PeerData*> peer);
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::producer<rpl::no_value, QString> request();
|
|
|
|
void requestBoosts(
|
|
|
|
const Data::BoostsListSlice::OffsetToken &token,
|
|
|
|
Fn<void(Data::BoostsListSlice)> done);
|
|
|
|
|
|
|
|
[[nodiscard]] Data::BoostStatus boostStatus() const;
|
|
|
|
|
|
|
|
static constexpr auto kFirstSlice = int(10);
|
|
|
|
static constexpr auto kLimit = int(40);
|
|
|
|
|
|
|
|
private:
|
|
|
|
const not_null<PeerData*> _peer;
|
|
|
|
Data::BoostStatus _boostStatus;
|
|
|
|
|
|
|
|
MTP::Sender _api;
|
|
|
|
mtpRequestId _requestId = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2023-04-26 20:05:12 +00:00
|
|
|
} // namespace Api
|