mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Destory stats sessions after a timeout.
This commit is contained in:
parent
1e6cf839e2
commit
9324ceeb24
8 changed files with 199 additions and 62 deletions
|
@ -18,6 +18,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
namespace Api {
|
namespace Api {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto kCheckRequestsTimer = 10 * crl::time(1000);
|
||||||
|
|
||||||
[[nodiscard]] Data::StatisticalGraph StatisticalGraphFromTL(
|
[[nodiscard]] Data::StatisticalGraph StatisticalGraphFromTL(
|
||||||
const MTPStatsGraph &tl) {
|
const MTPStatsGraph &tl) {
|
||||||
return tl.match([&](const MTPDstatsGraph &d) {
|
return tl.match([&](const MTPDstatsGraph &d) {
|
||||||
|
@ -188,36 +190,91 @@ namespace {
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
Statistics::Statistics(not_null<ChannelData*> channel)
|
Statistics::Statistics(not_null<ChannelData*> channel)
|
||||||
|
: StatisticsRequestSender(channel) {
|
||||||
|
}
|
||||||
|
|
||||||
|
StatisticsRequestSender::StatisticsRequestSender(not_null<ChannelData *> channel)
|
||||||
: _channel(channel)
|
: _channel(channel)
|
||||||
, _api(&channel->session().api().instance()) {
|
, _api(&_channel->session().api().instance())
|
||||||
|
, _timer([=] { checkRequests(); }) {
|
||||||
|
}
|
||||||
|
|
||||||
|
StatisticsRequestSender::~StatisticsRequestSender() {
|
||||||
|
for (const auto &[dcId, ids] : _requests) {
|
||||||
|
for (const auto id : ids) {
|
||||||
|
_channel->session().api().unregisterStatsRequest(dcId, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void StatisticsRequestSender::checkRequests() {
|
||||||
|
const auto api = &_channel->session().api();
|
||||||
|
for (auto i = begin(_requests); i != end(_requests);) {
|
||||||
|
for (auto j = begin(i->second); j != end(i->second);) {
|
||||||
|
if (_api.pending(*j)) {
|
||||||
|
++j;
|
||||||
|
} else {
|
||||||
|
_channel->session().api().unregisterStatsRequest(
|
||||||
|
i->first,
|
||||||
|
*j);
|
||||||
|
j = i->second.erase(j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i->second.empty()) {
|
||||||
|
i = _requests.erase(i);
|
||||||
|
} else {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_requests.empty()) {
|
||||||
|
_timer.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Request, typename, typename>
|
||||||
|
auto StatisticsRequestSender::makeRequest(Request &&request) {
|
||||||
|
const auto id = _api.allocateRequestId();
|
||||||
|
const auto dcId = _channel->owner().statsDcId(_channel);
|
||||||
|
if (dcId) {
|
||||||
|
_channel->session().api().registerStatsRequest(dcId, id);
|
||||||
|
_requests[dcId].emplace(id);
|
||||||
|
if (!_timer.isActive()) {
|
||||||
|
_timer.callEach(kCheckRequestsTimer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::move(_api.request(
|
||||||
|
std::forward<Request>(request)
|
||||||
|
).toDC(
|
||||||
|
dcId ? MTP::ShiftDcId(dcId, MTP::kStatsDcShift) : 0
|
||||||
|
).overrideId(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<rpl::no_value, QString> Statistics::request() {
|
rpl::producer<rpl::no_value, QString> Statistics::request() {
|
||||||
return [=](auto consumer) {
|
return [=](auto consumer) {
|
||||||
auto lifetime = rpl::lifetime();
|
auto lifetime = rpl::lifetime();
|
||||||
|
|
||||||
const auto dcId = _channel->owner().statsDcId(_channel);
|
if (!channel()->isMegagroup()) {
|
||||||
if (!_channel->isMegagroup()) {
|
makeRequest(MTPstats_GetBroadcastStats(
|
||||||
_api.request(MTPstats_GetBroadcastStats(
|
|
||||||
MTP_flags(MTPstats_GetBroadcastStats::Flags(0)),
|
MTP_flags(MTPstats_GetBroadcastStats::Flags(0)),
|
||||||
_channel->inputChannel
|
channel()->inputChannel
|
||||||
)).done([=](const MTPstats_BroadcastStats &result) {
|
)).done([=](const MTPstats_BroadcastStats &result) {
|
||||||
_channelStats = ChannelStatisticsFromTL(result.data());
|
_channelStats = ChannelStatisticsFromTL(result.data());
|
||||||
consumer.put_done();
|
consumer.put_done();
|
||||||
}).fail([=](const MTP::Error &error) {
|
}).fail([=](const MTP::Error &error) {
|
||||||
consumer.put_error_copy(error.type());
|
consumer.put_error_copy(error.type());
|
||||||
}).toDC(MTP::ShiftDcId(dcId, MTP::kStatsDcShift)).send();
|
}).send();
|
||||||
} else {
|
} else {
|
||||||
_api.request(MTPstats_GetMegagroupStats(
|
makeRequest(MTPstats_GetMegagroupStats(
|
||||||
MTP_flags(MTPstats_GetMegagroupStats::Flags(0)),
|
MTP_flags(MTPstats_GetMegagroupStats::Flags(0)),
|
||||||
_channel->inputChannel
|
channel()->inputChannel
|
||||||
)).done([=](const MTPstats_MegagroupStats &result) {
|
)).done([=](const MTPstats_MegagroupStats &result) {
|
||||||
_supergroupStats = SupergroupStatisticsFromTL(result.data());
|
const auto &data = result.data();
|
||||||
_channel->owner().processUsers(result.data().vusers());
|
_supergroupStats = SupergroupStatisticsFromTL(data);
|
||||||
|
channel()->owner().processUsers(data.vusers());
|
||||||
consumer.put_done();
|
consumer.put_done();
|
||||||
}).fail([=](const MTP::Error &error) {
|
}).fail([=](const MTP::Error &error) {
|
||||||
consumer.put_error_copy(error.type());
|
consumer.put_error_copy(error.type());
|
||||||
}).toDC(MTP::ShiftDcId(dcId, MTP::kStatsDcShift)).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
return lifetime;
|
return lifetime;
|
||||||
|
@ -229,10 +286,9 @@ Statistics::GraphResult Statistics::requestZoom(
|
||||||
float64 x) {
|
float64 x) {
|
||||||
return [=](auto consumer) {
|
return [=](auto consumer) {
|
||||||
auto lifetime = rpl::lifetime();
|
auto lifetime = rpl::lifetime();
|
||||||
const auto dcId = _channel->owner().statsDcId(_channel);
|
|
||||||
const auto wasEmpty = _zoomDeque.empty();
|
const auto wasEmpty = _zoomDeque.empty();
|
||||||
_zoomDeque.push_back([=] {
|
_zoomDeque.push_back([=] {
|
||||||
_api.request(MTPstats_LoadAsyncGraph(
|
makeRequest(MTPstats_LoadAsyncGraph(
|
||||||
MTP_flags(x
|
MTP_flags(x
|
||||||
? MTPstats_LoadAsyncGraph::Flag::f_x
|
? MTPstats_LoadAsyncGraph::Flag::f_x
|
||||||
: MTPstats_LoadAsyncGraph::Flag(0)),
|
: MTPstats_LoadAsyncGraph::Flag(0)),
|
||||||
|
@ -249,7 +305,7 @@ Statistics::GraphResult Statistics::requestZoom(
|
||||||
}
|
}
|
||||||
}).fail([=](const MTP::Error &error) {
|
}).fail([=](const MTP::Error &error) {
|
||||||
consumer.put_error_copy(error.type());
|
consumer.put_error_copy(error.type());
|
||||||
}).toDC(MTP::ShiftDcId(dcId, MTP::kStatsDcShift)).send();
|
}).send();
|
||||||
});
|
});
|
||||||
if (wasEmpty) {
|
if (wasEmpty) {
|
||||||
_zoomDeque.front()();
|
_zoomDeque.front()();
|
||||||
|
@ -270,9 +326,8 @@ Data::SupergroupStatistics Statistics::supergroupStats() const {
|
||||||
PublicForwards::PublicForwards(
|
PublicForwards::PublicForwards(
|
||||||
not_null<ChannelData*> channel,
|
not_null<ChannelData*> channel,
|
||||||
FullMsgId fullId)
|
FullMsgId fullId)
|
||||||
: _channel(channel)
|
: StatisticsRequestSender(channel)
|
||||||
, _fullId(fullId)
|
, _fullId(fullId) {
|
||||||
, _api(&channel->session().api().instance()) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PublicForwards::request(
|
void PublicForwards::request(
|
||||||
|
@ -281,20 +336,19 @@ void PublicForwards::request(
|
||||||
if (_requestId) {
|
if (_requestId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto dcId = _channel->owner().statsDcId(_channel);
|
const auto offsetPeer = channel()->owner().peer(token.fullId.peer);
|
||||||
const auto offsetPeer = _channel->owner().peer(token.fullId.peer);
|
|
||||||
const auto tlOffsetPeer = offsetPeer
|
const auto tlOffsetPeer = offsetPeer
|
||||||
? offsetPeer->input
|
? offsetPeer->input
|
||||||
: MTP_inputPeerEmpty();
|
: MTP_inputPeerEmpty();
|
||||||
constexpr auto kLimit = tl::make_int(100);
|
constexpr auto kLimit = tl::make_int(100);
|
||||||
_requestId = _api.request(MTPstats_GetMessagePublicForwards(
|
_requestId = makeRequest(MTPstats_GetMessagePublicForwards(
|
||||||
_channel->inputChannel,
|
channel()->inputChannel,
|
||||||
MTP_int(_fullId.msg),
|
MTP_int(_fullId.msg),
|
||||||
MTP_int(token.rate),
|
MTP_int(token.rate),
|
||||||
tlOffsetPeer,
|
tlOffsetPeer,
|
||||||
MTP_int(token.fullId.msg),
|
MTP_int(token.fullId.msg),
|
||||||
kLimit
|
kLimit
|
||||||
)).done([=, channel = _channel](const MTPmessages_Messages &result) {
|
)).done([=, channel = channel()](const MTPmessages_Messages &result) {
|
||||||
using Messages = QVector<FullMsgId>;
|
using Messages = QVector<FullMsgId>;
|
||||||
_requestId = 0;
|
_requestId = 0;
|
||||||
|
|
||||||
|
@ -364,16 +418,15 @@ void PublicForwards::request(
|
||||||
});
|
});
|
||||||
}).fail([=] {
|
}).fail([=] {
|
||||||
_requestId = 0;
|
_requestId = 0;
|
||||||
}).toDC(MTP::ShiftDcId(dcId, MTP::kStatsDcShift)).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageStatistics::MessageStatistics(
|
MessageStatistics::MessageStatistics(
|
||||||
not_null<ChannelData*> channel,
|
not_null<ChannelData*> channel,
|
||||||
FullMsgId fullId)
|
FullMsgId fullId)
|
||||||
: _publicForwards(channel, fullId)
|
: StatisticsRequestSender(channel)
|
||||||
, _channel(channel)
|
, _publicForwards(channel, fullId)
|
||||||
, _fullId(fullId)
|
, _fullId(fullId) {
|
||||||
, _api(&channel->session().api().instance()) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Data::PublicForwardsSlice MessageStatistics::firstSlice() const {
|
Data::PublicForwardsSlice MessageStatistics::firstSlice() const {
|
||||||
|
@ -381,11 +434,9 @@ Data::PublicForwardsSlice MessageStatistics::firstSlice() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageStatistics::request(Fn<void(Data::MessageStatistics)> done) {
|
void MessageStatistics::request(Fn<void(Data::MessageStatistics)> done) {
|
||||||
if (_channel->isMegagroup()) {
|
if (channel()->isMegagroup()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto dcId = _channel->owner().statsDcId(_channel);
|
|
||||||
|
|
||||||
const auto requestFirstPublicForwards = [=](
|
const auto requestFirstPublicForwards = [=](
|
||||||
const Data::StatisticalGraph &messageGraph,
|
const Data::StatisticalGraph &messageGraph,
|
||||||
const Data::StatisticsMessageInteractionInfo &info) {
|
const Data::StatisticsMessageInteractionInfo &info) {
|
||||||
|
@ -403,8 +454,8 @@ void MessageStatistics::request(Fn<void(Data::MessageStatistics)> done) {
|
||||||
|
|
||||||
const auto requestPrivateForwards = [=](
|
const auto requestPrivateForwards = [=](
|
||||||
const Data::StatisticalGraph &messageGraph) {
|
const Data::StatisticalGraph &messageGraph) {
|
||||||
_api.request(MTPchannels_GetMessages(
|
api().request(MTPchannels_GetMessages(
|
||||||
_channel->inputChannel,
|
channel()->inputChannel,
|
||||||
MTP_vector<MTPInputMessage>(
|
MTP_vector<MTPInputMessage>(
|
||||||
1,
|
1,
|
||||||
MTP_inputMessageID(MTP_int(_fullId.msg))))
|
MTP_inputMessageID(MTP_int(_fullId.msg))))
|
||||||
|
@ -444,17 +495,16 @@ void MessageStatistics::request(Fn<void(Data::MessageStatistics)> done) {
|
||||||
}).send();
|
}).send();
|
||||||
};
|
};
|
||||||
|
|
||||||
_api.request(MTPstats_GetMessageStats(
|
makeRequest(MTPstats_GetMessageStats(
|
||||||
MTP_flags(MTPstats_GetMessageStats::Flags(0)),
|
MTP_flags(MTPstats_GetMessageStats::Flags(0)),
|
||||||
_channel->inputChannel,
|
channel()->inputChannel,
|
||||||
MTP_int(_fullId.msg.bare)
|
MTP_int(_fullId.msg.bare)
|
||||||
)).done([=](const MTPstats_MessageStats &result) {
|
)).done([=](const MTPstats_MessageStats &result) {
|
||||||
requestPrivateForwards(
|
requestPrivateForwards(
|
||||||
StatisticalGraphFromTL(result.data().vviews_graph()));
|
StatisticalGraphFromTL(result.data().vviews_graph()));
|
||||||
}).fail([=](const MTP::Error &error) {
|
}).fail([=](const MTP::Error &error) {
|
||||||
requestPrivateForwards({});
|
requestPrivateForwards({});
|
||||||
}).toDC(MTP::ShiftDcId(dcId, MTP::kStatsDcShift)).send();
|
}).send();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Boosts::Boosts(not_null<PeerData*> peer)
|
Boosts::Boosts(not_null<PeerData*> peer)
|
||||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "base/timer.h"
|
||||||
#include "data/data_boosts.h"
|
#include "data/data_boosts.h"
|
||||||
#include "data/data_statistics.h"
|
#include "data/data_statistics.h"
|
||||||
#include "mtproto/sender.h"
|
#include "mtproto/sender.h"
|
||||||
|
@ -16,7 +17,35 @@ class PeerData;
|
||||||
|
|
||||||
namespace Api {
|
namespace Api {
|
||||||
|
|
||||||
class Statistics final {
|
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 {
|
||||||
public:
|
public:
|
||||||
explicit Statistics(not_null<ChannelData*> channel);
|
explicit Statistics(not_null<ChannelData*> channel);
|
||||||
|
|
||||||
|
@ -30,34 +59,29 @@ public:
|
||||||
[[nodiscard]] Data::SupergroupStatistics supergroupStats() const;
|
[[nodiscard]] Data::SupergroupStatistics supergroupStats() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const not_null<ChannelData*> _channel;
|
|
||||||
Data::ChannelStatistics _channelStats;
|
Data::ChannelStatistics _channelStats;
|
||||||
Data::SupergroupStatistics _supergroupStats;
|
Data::SupergroupStatistics _supergroupStats;
|
||||||
MTP::Sender _api;
|
|
||||||
|
|
||||||
std::deque<Fn<void()>> _zoomDeque;
|
std::deque<Fn<void()>> _zoomDeque;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class PublicForwards final {
|
class PublicForwards final : public StatisticsRequestSender {
|
||||||
public:
|
public:
|
||||||
explicit PublicForwards(not_null<ChannelData*> channel, FullMsgId fullId);
|
PublicForwards(not_null<ChannelData*> channel, FullMsgId fullId);
|
||||||
|
|
||||||
void request(
|
void request(
|
||||||
const Data::PublicForwardsSlice::OffsetToken &token,
|
const Data::PublicForwardsSlice::OffsetToken &token,
|
||||||
Fn<void(Data::PublicForwardsSlice)> done);
|
Fn<void(Data::PublicForwardsSlice)> done);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const not_null<ChannelData*> _channel;
|
|
||||||
const FullMsgId _fullId;
|
const FullMsgId _fullId;
|
||||||
mtpRequestId _requestId = 0;
|
mtpRequestId _requestId = 0;
|
||||||
int _lastTotal = 0;
|
int _lastTotal = 0;
|
||||||
|
|
||||||
MTP::Sender _api;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class MessageStatistics final {
|
class MessageStatistics final : public StatisticsRequestSender {
|
||||||
public:
|
public:
|
||||||
explicit MessageStatistics(
|
explicit MessageStatistics(
|
||||||
not_null<ChannelData*> channel,
|
not_null<ChannelData*> channel,
|
||||||
|
@ -69,13 +93,11 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PublicForwards _publicForwards;
|
PublicForwards _publicForwards;
|
||||||
const not_null<ChannelData*> _channel;
|
|
||||||
const FullMsgId _fullId;
|
const FullMsgId _fullId;
|
||||||
|
|
||||||
Data::PublicForwardsSlice _firstSlice;
|
Data::PublicForwardsSlice _firstSlice;
|
||||||
|
|
||||||
mtpRequestId _requestId = 0;
|
mtpRequestId _requestId = 0;
|
||||||
MTP::Sender _api;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -114,6 +114,7 @@ constexpr auto kStickersByEmojiInvalidateTimeout = crl::time(6 * 1000);
|
||||||
constexpr auto kNotifySettingSaveTimeout = crl::time(1000);
|
constexpr auto kNotifySettingSaveTimeout = crl::time(1000);
|
||||||
constexpr auto kDialogsFirstLoad = 20;
|
constexpr auto kDialogsFirstLoad = 20;
|
||||||
constexpr auto kDialogsPerPage = 500;
|
constexpr auto kDialogsPerPage = 500;
|
||||||
|
constexpr auto kStatsSessionKillTimeout = 10 * crl::time(1000);
|
||||||
|
|
||||||
using PhotoFileLocationId = Data::PhotoFileLocationId;
|
using PhotoFileLocationId = Data::PhotoFileLocationId;
|
||||||
using DocumentFileLocationId = Data::DocumentFileLocationId;
|
using DocumentFileLocationId = Data::DocumentFileLocationId;
|
||||||
|
@ -159,6 +160,7 @@ ApiWrap::ApiWrap(not_null<Main::Session*> session)
|
||||||
, _fileLoader(std::make_unique<TaskQueue>(kFileLoaderQueueStopTimeout))
|
, _fileLoader(std::make_unique<TaskQueue>(kFileLoaderQueueStopTimeout))
|
||||||
, _topPromotionTimer([=] { refreshTopPromotion(); })
|
, _topPromotionTimer([=] { refreshTopPromotion(); })
|
||||||
, _updateNotifyTimer([=] { sendNotifySettingsUpdates(); })
|
, _updateNotifyTimer([=] { sendNotifySettingsUpdates(); })
|
||||||
|
, _statsSessionKillTimer([=] { checkStatsSessions(); })
|
||||||
, _authorizations(std::make_unique<Api::Authorizations>(this))
|
, _authorizations(std::make_unique<Api::Authorizations>(this))
|
||||||
, _attachedStickers(std::make_unique<Api::AttachedStickers>(this))
|
, _attachedStickers(std::make_unique<Api::AttachedStickers>(this))
|
||||||
, _blockedPeers(std::make_unique<Api::BlockedPeers>(this))
|
, _blockedPeers(std::make_unique<Api::BlockedPeers>(this))
|
||||||
|
@ -4287,6 +4289,32 @@ void ApiWrap::saveSelfBio(const QString &text) {
|
||||||
}).send();
|
}).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ApiWrap::registerStatsRequest(MTP::DcId dcId, mtpRequestId id) {
|
||||||
|
_statsRequests[dcId].emplace(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApiWrap::unregisterStatsRequest(MTP::DcId dcId, mtpRequestId id) {
|
||||||
|
const auto i = _statsRequests.find(dcId);
|
||||||
|
Assert(i != end(_statsRequests));
|
||||||
|
const auto removed = i->second.remove(id);
|
||||||
|
Assert(removed);
|
||||||
|
if (i->second.empty()) {
|
||||||
|
_statsSessionKillTimer.callOnce(kStatsSessionKillTimeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApiWrap::checkStatsSessions() {
|
||||||
|
for (auto i = begin(_statsRequests); i != end(_statsRequests);) {
|
||||||
|
if (i->second.empty()) {
|
||||||
|
instance().killSession(
|
||||||
|
MTP::ShiftDcId(i->first, MTP::kStatsDcShift));
|
||||||
|
i = _statsRequests.erase(i);
|
||||||
|
} else {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Api::Authorizations &ApiWrap::authorizations() {
|
Api::Authorizations &ApiWrap::authorizations() {
|
||||||
return *_authorizations;
|
return *_authorizations;
|
||||||
}
|
}
|
||||||
|
|
|
@ -369,6 +369,9 @@ public:
|
||||||
|
|
||||||
void saveSelfBio(const QString &text);
|
void saveSelfBio(const QString &text);
|
||||||
|
|
||||||
|
void registerStatsRequest(MTP::DcId dcId, mtpRequestId id);
|
||||||
|
void unregisterStatsRequest(MTP::DcId dcId, mtpRequestId id);
|
||||||
|
|
||||||
[[nodiscard]] Api::Authorizations &authorizations();
|
[[nodiscard]] Api::Authorizations &authorizations();
|
||||||
[[nodiscard]] Api::AttachedStickers &attachedStickers();
|
[[nodiscard]] Api::AttachedStickers &attachedStickers();
|
||||||
[[nodiscard]] Api::BlockedPeers &blockedPeers();
|
[[nodiscard]] Api::BlockedPeers &blockedPeers();
|
||||||
|
@ -547,6 +550,8 @@ private:
|
||||||
not_null<ChannelData*> channel);
|
not_null<ChannelData*> channel);
|
||||||
void migrateFail(not_null<PeerData*> peer, const QString &error);
|
void migrateFail(not_null<PeerData*> peer, const QString &error);
|
||||||
|
|
||||||
|
void checkStatsSessions();
|
||||||
|
|
||||||
const not_null<Main::Session*> _session;
|
const not_null<Main::Session*> _session;
|
||||||
|
|
||||||
base::flat_map<QString, int> _modifyRequests;
|
base::flat_map<QString, int> _modifyRequests;
|
||||||
|
@ -683,6 +688,9 @@ private:
|
||||||
QString requestedText;
|
QString requestedText;
|
||||||
} _bio;
|
} _bio;
|
||||||
|
|
||||||
|
base::flat_map<MTP::DcId, base::flat_set<mtpRequestId>> _statsRequests;
|
||||||
|
base::Timer _statsSessionKillTimer;
|
||||||
|
|
||||||
const std::unique_ptr<Api::Authorizations> _authorizations;
|
const std::unique_ptr<Api::Authorizations> _authorizations;
|
||||||
const std::unique_ptr<Api::AttachedStickers> _attachedStickers;
|
const std::unique_ptr<Api::AttachedStickers> _attachedStickers;
|
||||||
const std::unique_ptr<Api::BlockedPeers> _blockedPeers;
|
const std::unique_ptr<Api::BlockedPeers> _blockedPeers;
|
||||||
|
|
|
@ -4537,8 +4537,12 @@ MTP::DcId Session::statsDcId(not_null<ChannelData*> channel) {
|
||||||
return (it == end(_channelStatsDcIds)) ? MTP::DcId(0) : it->second;
|
return (it == end(_channelStatsDcIds)) ? MTP::DcId(0) : it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::applyStatsDcId(not_null<ChannelData*> channel, MTP::DcId dcId) {
|
void Session::applyStatsDcId(
|
||||||
_channelStatsDcIds[channel] = dcId;
|
not_null<ChannelData*> channel,
|
||||||
|
MTP::DcId dcId) {
|
||||||
|
if (dcId != channel->session().mainDcId()) {
|
||||||
|
_channelStatsDcIds[channel] = dcId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::webViewResultSent(WebViewResultSent &&sent) {
|
void Session::webViewResultSent(WebViewResultSent &&sent) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ constexpr auto kUpdaterDcShift = 0x03;
|
||||||
constexpr auto kExportDcShift = 0x04;
|
constexpr auto kExportDcShift = 0x04;
|
||||||
constexpr auto kExportMediaDcShift = 0x05;
|
constexpr auto kExportMediaDcShift = 0x05;
|
||||||
constexpr auto kGroupCallStreamDcShift = 0x06;
|
constexpr auto kGroupCallStreamDcShift = 0x06;
|
||||||
constexpr auto kStatsDcShift = 0x06;
|
constexpr auto kStatsDcShift = 0x07;
|
||||||
constexpr auto kMaxMediaDcCount = 0x10;
|
constexpr auto kMaxMediaDcCount = 0x10;
|
||||||
constexpr auto kBaseDownloadDcShift = 0x10;
|
constexpr auto kBaseDownloadDcShift = 0x10;
|
||||||
constexpr auto kBaseUploadDcShift = 0x20;
|
constexpr auto kBaseUploadDcShift = 0x20;
|
||||||
|
|
|
@ -150,8 +150,11 @@ public:
|
||||||
ResponseHandler &&callbacks = {},
|
ResponseHandler &&callbacks = {},
|
||||||
ShiftedDcId shiftedDcId = 0,
|
ShiftedDcId shiftedDcId = 0,
|
||||||
crl::time msCanWait = 0,
|
crl::time msCanWait = 0,
|
||||||
mtpRequestId afterRequestId = 0) {
|
mtpRequestId afterRequestId = 0,
|
||||||
const auto requestId = details::GetNextRequestId();
|
mtpRequestId overrideRequestId = 0) {
|
||||||
|
const auto requestId = overrideRequestId
|
||||||
|
? overrideRequestId
|
||||||
|
: details::GetNextRequestId();
|
||||||
sendSerialized(
|
sendSerialized(
|
||||||
requestId,
|
requestId,
|
||||||
details::SerializedRequest::Serialize(request),
|
details::SerializedRequest::Serialize(request),
|
||||||
|
@ -169,13 +172,15 @@ public:
|
||||||
FailHandler &&onFail = nullptr,
|
FailHandler &&onFail = nullptr,
|
||||||
ShiftedDcId shiftedDcId = 0,
|
ShiftedDcId shiftedDcId = 0,
|
||||||
crl::time msCanWait = 0,
|
crl::time msCanWait = 0,
|
||||||
mtpRequestId afterRequestId = 0) {
|
mtpRequestId afterRequestId = 0,
|
||||||
|
mtpRequestId overrideRequestId = 0) {
|
||||||
return send(
|
return send(
|
||||||
request,
|
request,
|
||||||
ResponseHandler{ std::move(onDone), std::move(onFail) },
|
ResponseHandler{ std::move(onDone), std::move(onFail) },
|
||||||
shiftedDcId,
|
shiftedDcId,
|
||||||
msCanWait,
|
msCanWait,
|
||||||
afterRequestId);
|
afterRequestId,
|
||||||
|
overrideRequestId);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Request>
|
template <typename Request>
|
||||||
|
|
|
@ -130,6 +130,9 @@ class Sender {
|
||||||
void setToDC(ShiftedDcId dcId) noexcept {
|
void setToDC(ShiftedDcId dcId) noexcept {
|
||||||
_dcId = dcId;
|
_dcId = dcId;
|
||||||
}
|
}
|
||||||
|
void setOverrideRequestId(mtpRequestId id) noexcept {
|
||||||
|
_overrideRequestId = id;
|
||||||
|
}
|
||||||
void setCanWait(crl::time ms) noexcept {
|
void setCanWait(crl::time ms) noexcept {
|
||||||
_canWait = ms;
|
_canWait = ms;
|
||||||
}
|
}
|
||||||
|
@ -147,16 +150,16 @@ class Sender {
|
||||||
_afterRequestId = requestId;
|
_afterRequestId = requestId;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShiftedDcId takeDcId() const noexcept {
|
[[nodiscard]] ShiftedDcId takeDcId() const noexcept {
|
||||||
return _dcId;
|
return _dcId;
|
||||||
}
|
}
|
||||||
crl::time takeCanWait() const noexcept {
|
[[nodiscard]] crl::time takeCanWait() const noexcept {
|
||||||
return _canWait;
|
return _canWait;
|
||||||
}
|
}
|
||||||
DoneHandler takeOnDone() noexcept {
|
[[nodiscard]] DoneHandler takeOnDone() noexcept {
|
||||||
return std::move(_done);
|
return std::move(_done);
|
||||||
}
|
}
|
||||||
FailHandler takeOnFail() {
|
[[nodiscard]] FailHandler takeOnFail() {
|
||||||
return v::match(_fail, [&](auto &value) {
|
return v::match(_fail, [&](auto &value) {
|
||||||
return MakeFailHandler(
|
return MakeFailHandler(
|
||||||
_sender,
|
_sender,
|
||||||
|
@ -164,11 +167,14 @@ class Sender {
|
||||||
_failSkipPolicy);
|
_failSkipPolicy);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
mtpRequestId takeAfter() const noexcept {
|
[[nodiscard]] mtpRequestId takeAfter() const noexcept {
|
||||||
return _afterRequestId;
|
return _afterRequestId;
|
||||||
}
|
}
|
||||||
|
[[nodiscard]] mtpRequestId takeOverrideRequestId() const noexcept {
|
||||||
|
return _overrideRequestId;
|
||||||
|
}
|
||||||
|
|
||||||
not_null<Sender*> sender() const noexcept {
|
[[nodiscard]] not_null<Sender*> sender() const noexcept {
|
||||||
return _sender;
|
return _sender;
|
||||||
}
|
}
|
||||||
void registerRequest(mtpRequestId requestId) {
|
void registerRequest(mtpRequestId requestId) {
|
||||||
|
@ -187,6 +193,7 @@ class Sender {
|
||||||
FailFullHandler> _fail;
|
FailFullHandler> _fail;
|
||||||
FailSkipPolicy _failSkipPolicy = FailSkipPolicy::Simple;
|
FailSkipPolicy _failSkipPolicy = FailSkipPolicy::Simple;
|
||||||
mtpRequestId _afterRequestId = 0;
|
mtpRequestId _afterRequestId = 0;
|
||||||
|
mtpRequestId _overrideRequestId = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -207,9 +214,10 @@ public:
|
||||||
: RequestBuilder(sender)
|
: RequestBuilder(sender)
|
||||||
, _request(std::move(request)) {
|
, _request(std::move(request)) {
|
||||||
}
|
}
|
||||||
SpecificRequestBuilder(SpecificRequestBuilder &&other) = default;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
SpecificRequestBuilder(SpecificRequestBuilder &&other) = default;
|
||||||
|
|
||||||
[[nodiscard]] SpecificRequestBuilder &toDC(ShiftedDcId dcId) noexcept {
|
[[nodiscard]] SpecificRequestBuilder &toDC(ShiftedDcId dcId) noexcept {
|
||||||
setToDC(dcId);
|
setToDC(dcId);
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -218,6 +226,10 @@ public:
|
||||||
setCanWait(ms);
|
setCanWait(ms);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
[[nodiscard]] SpecificRequestBuilder &overrideId(mtpRequestId id) noexcept {
|
||||||
|
setOverrideRequestId(id);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
using Result = typename Request::ResponseType;
|
using Result = typename Request::ResponseType;
|
||||||
[[nodiscard]] SpecificRequestBuilder &done(
|
[[nodiscard]] SpecificRequestBuilder &done(
|
||||||
|
@ -295,7 +307,8 @@ public:
|
||||||
takeOnFail(),
|
takeOnFail(),
|
||||||
takeDcId(),
|
takeDcId(),
|
||||||
takeCanWait(),
|
takeCanWait(),
|
||||||
takeAfter());
|
takeAfter(),
|
||||||
|
takeOverrideRequestId());
|
||||||
registerRequest(id);
|
registerRequest(id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -347,6 +360,13 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] mtpRequestId allocateRequestId() noexcept {
|
||||||
|
return details::GetNextRequestId();
|
||||||
|
}
|
||||||
|
[[nodiscard]] bool pending(mtpRequestId requestId) noexcept {
|
||||||
|
return _requests.contains(requestId);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class RequestWrap {
|
class RequestWrap {
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Reference in a new issue