mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Fixed Api requests for statistics with non-default DC.
This commit is contained in:
parent
468d4c5e4f
commit
1e6cf839e2
7 changed files with 41 additions and 61 deletions
|
@ -187,40 +187,37 @@ namespace {
|
|||
|
||||
} // namespace
|
||||
|
||||
Statistics::Statistics(not_null<ApiWrap*> api)
|
||||
: _api(&api->instance()) {
|
||||
Statistics::Statistics(not_null<ChannelData*> channel)
|
||||
: _channel(channel)
|
||||
, _api(&channel->session().api().instance()) {
|
||||
}
|
||||
|
||||
rpl::producer<rpl::no_value, QString> Statistics::request(
|
||||
not_null<PeerData*> peer) {
|
||||
rpl::producer<rpl::no_value, QString> Statistics::request() {
|
||||
return [=](auto consumer) {
|
||||
auto lifetime = rpl::lifetime();
|
||||
const auto channel = peer->asChannel();
|
||||
if (!channel) {
|
||||
return lifetime;
|
||||
}
|
||||
|
||||
if (!channel->isMegagroup()) {
|
||||
const auto dcId = _channel->owner().statsDcId(_channel);
|
||||
if (!_channel->isMegagroup()) {
|
||||
_api.request(MTPstats_GetBroadcastStats(
|
||||
MTP_flags(MTPstats_GetBroadcastStats::Flags(0)),
|
||||
channel->inputChannel
|
||||
_channel->inputChannel
|
||||
)).done([=](const MTPstats_BroadcastStats &result) {
|
||||
_channelStats = ChannelStatisticsFromTL(result.data());
|
||||
consumer.put_done();
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
consumer.put_error_copy(error.type());
|
||||
}).send();
|
||||
}).toDC(MTP::ShiftDcId(dcId, MTP::kStatsDcShift)).send();
|
||||
} else {
|
||||
_api.request(MTPstats_GetMegagroupStats(
|
||||
MTP_flags(MTPstats_GetMegagroupStats::Flags(0)),
|
||||
channel->inputChannel
|
||||
_channel->inputChannel
|
||||
)).done([=](const MTPstats_MegagroupStats &result) {
|
||||
_supergroupStats = SupergroupStatisticsFromTL(result.data());
|
||||
peer->owner().processUsers(result.data().vusers());
|
||||
_channel->owner().processUsers(result.data().vusers());
|
||||
consumer.put_done();
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
consumer.put_error_copy(error.type());
|
||||
}).send();
|
||||
}).toDC(MTP::ShiftDcId(dcId, MTP::kStatsDcShift)).send();
|
||||
}
|
||||
|
||||
return lifetime;
|
||||
|
@ -228,15 +225,11 @@ rpl::producer<rpl::no_value, QString> Statistics::request(
|
|||
}
|
||||
|
||||
Statistics::GraphResult Statistics::requestZoom(
|
||||
not_null<PeerData*> peer,
|
||||
const QString &token,
|
||||
float64 x) {
|
||||
return [=](auto consumer) {
|
||||
auto lifetime = rpl::lifetime();
|
||||
const auto channel = peer->asChannel();
|
||||
if (!channel) {
|
||||
return lifetime;
|
||||
}
|
||||
const auto dcId = _channel->owner().statsDcId(_channel);
|
||||
const auto wasEmpty = _zoomDeque.empty();
|
||||
_zoomDeque.push_back([=] {
|
||||
_api.request(MTPstats_LoadAsyncGraph(
|
||||
|
@ -256,7 +249,7 @@ Statistics::GraphResult Statistics::requestZoom(
|
|||
}
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
consumer.put_error_copy(error.type());
|
||||
}).send();
|
||||
}).toDC(MTP::ShiftDcId(dcId, MTP::kStatsDcShift)).send();
|
||||
});
|
||||
if (wasEmpty) {
|
||||
_zoomDeque.front()();
|
||||
|
@ -266,32 +259,6 @@ Statistics::GraphResult Statistics::requestZoom(
|
|||
};
|
||||
}
|
||||
|
||||
Statistics::GraphResult Statistics::requestMessage(
|
||||
not_null<PeerData*> 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;
|
||||
}
|
||||
|
@ -314,6 +281,7 @@ void PublicForwards::request(
|
|||
if (_requestId) {
|
||||
return;
|
||||
}
|
||||
const auto dcId = _channel->owner().statsDcId(_channel);
|
||||
const auto offsetPeer = _channel->owner().peer(token.fullId.peer);
|
||||
const auto tlOffsetPeer = offsetPeer
|
||||
? offsetPeer->input
|
||||
|
@ -396,7 +364,7 @@ void PublicForwards::request(
|
|||
});
|
||||
}).fail([=] {
|
||||
_requestId = 0;
|
||||
}).send();
|
||||
}).toDC(MTP::ShiftDcId(dcId, MTP::kStatsDcShift)).send();
|
||||
}
|
||||
|
||||
MessageStatistics::MessageStatistics(
|
||||
|
@ -416,6 +384,7 @@ void MessageStatistics::request(Fn<void(Data::MessageStatistics)> done) {
|
|||
if (_channel->isMegagroup()) {
|
||||
return;
|
||||
}
|
||||
const auto dcId = _channel->owner().statsDcId(_channel);
|
||||
|
||||
const auto requestFirstPublicForwards = [=](
|
||||
const Data::StatisticalGraph &messageGraph,
|
||||
|
@ -484,7 +453,7 @@ void MessageStatistics::request(Fn<void(Data::MessageStatistics)> done) {
|
|||
StatisticalGraphFromTL(result.data().vviews_graph()));
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
requestPrivateForwards({});
|
||||
}).send();
|
||||
}).toDC(MTP::ShiftDcId(dcId, MTP::kStatsDcShift)).send();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_statistics.h"
|
||||
#include "mtproto/sender.h"
|
||||
|
||||
class ApiWrap;
|
||||
class ChannelData;
|
||||
class PeerData;
|
||||
|
||||
|
@ -19,23 +18,19 @@ namespace Api {
|
|||
|
||||
class Statistics final {
|
||||
public:
|
||||
explicit Statistics(not_null<ApiWrap*> api);
|
||||
explicit Statistics(not_null<ChannelData*> channel);
|
||||
|
||||
[[nodiscard]] rpl::producer<rpl::no_value, QString> request(
|
||||
not_null<PeerData*> peer);
|
||||
[[nodiscard]] rpl::producer<rpl::no_value, QString> request();
|
||||
using GraphResult = rpl::producer<Data::StatisticalGraph, QString>;
|
||||
[[nodiscard]] GraphResult requestZoom(
|
||||
not_null<PeerData*> peer,
|
||||
const QString &token,
|
||||
float64 x);
|
||||
[[nodiscard]] GraphResult requestMessage(
|
||||
not_null<PeerData*> peer,
|
||||
MsgId msgId);
|
||||
|
||||
[[nodiscard]] Data::ChannelStatistics channelStats() const;
|
||||
[[nodiscard]] Data::SupergroupStatistics supergroupStats() const;
|
||||
|
||||
private:
|
||||
const not_null<ChannelData*> _channel;
|
||||
Data::ChannelStatistics _channelStats;
|
||||
Data::SupergroupStatistics _supergroupStats;
|
||||
MTP::Sender _api;
|
||||
|
|
|
@ -1120,6 +1120,10 @@ void ApplyChannelUpdate(
|
|||
channel,
|
||||
update.vnotify_settings());
|
||||
|
||||
if (update.vstats_dc()) {
|
||||
channel->owner().applyStatsDcId(channel, update.vstats_dc()->v);
|
||||
}
|
||||
|
||||
if (const auto sendAs = update.vdefault_send_as()) {
|
||||
session->sendAsPeers().setChosen(channel, peerFromMTP(*sendAs));
|
||||
} else {
|
||||
|
|
|
@ -4532,6 +4532,15 @@ uint64 Session::wallpapersHash() const {
|
|||
return _wallpapersHash;
|
||||
}
|
||||
|
||||
MTP::DcId Session::statsDcId(not_null<ChannelData*> channel) {
|
||||
const auto it = _channelStatsDcIds.find(channel);
|
||||
return (it == end(_channelStatsDcIds)) ? MTP::DcId(0) : it->second;
|
||||
}
|
||||
|
||||
void Session::applyStatsDcId(not_null<ChannelData*> channel, MTP::DcId dcId) {
|
||||
_channelStatsDcIds[channel] = dcId;
|
||||
}
|
||||
|
||||
void Session::webViewResultSent(WebViewResultSent &&sent) {
|
||||
return _webViewResultSent.fire(std::move(sent));
|
||||
}
|
||||
|
|
|
@ -730,6 +730,9 @@ public:
|
|||
[[nodiscard]] auto peerDecorationsUpdated() const
|
||||
-> rpl::producer<not_null<PeerData*>>;
|
||||
|
||||
void applyStatsDcId(not_null<ChannelData*>, MTP::DcId);
|
||||
[[nodiscard]] MTP::DcId statsDcId(not_null<ChannelData*>);
|
||||
|
||||
void clearLocalStorage();
|
||||
|
||||
private:
|
||||
|
@ -1014,6 +1017,8 @@ private:
|
|||
base::flat_map<not_null<UserData*>, TimeId> _watchingForOffline;
|
||||
base::Timer _watchForOfflineTimer;
|
||||
|
||||
base::flat_map<not_null<ChannelData*>, MTP::DcId> _channelStatsDcIds;
|
||||
|
||||
rpl::event_stream<WebViewResultSent> _webViewResultSent;
|
||||
|
||||
rpl::event_stream<not_null<PeerData*>> _peerDecorationsUpdated;
|
||||
|
|
|
@ -91,7 +91,6 @@ void ProcessZoom(
|
|||
widget->zoomRequests(
|
||||
) | rpl::start_with_next([=](float64 x) {
|
||||
d.api->requestZoom(
|
||||
d.peer,
|
||||
zoomToken,
|
||||
x
|
||||
) | rpl::start_with_next_error_done([=](
|
||||
|
@ -144,7 +143,6 @@ void FillStatistic(
|
|||
m);
|
||||
|
||||
descriptor.api->requestZoom(
|
||||
descriptor.peer,
|
||||
graphData.zoomToken,
|
||||
0
|
||||
) | rpl::start_with_next_error_done([=, graphPtr = &graphData](
|
||||
|
@ -524,7 +522,7 @@ void InnerWidget::load() {
|
|||
|
||||
const auto descriptor = Descriptor{
|
||||
_peer,
|
||||
lifetime().make_state<Api::Statistics>(&_peer->session().api()),
|
||||
lifetime().make_state<Api::Statistics>(_peer->asChannel()),
|
||||
_controller->uiShow()->toastParent(),
|
||||
};
|
||||
|
||||
|
@ -543,7 +541,6 @@ void InnerWidget::load() {
|
|||
) | rpl::take(1) | rpl::start_with_next([=] {
|
||||
if (!_contextId) {
|
||||
descriptor.api->request(
|
||||
descriptor.peer
|
||||
) | rpl::start_with_done([=] {
|
||||
_state.stats = Data::AnyStatistics{
|
||||
descriptor.api->channelStats(),
|
||||
|
@ -575,7 +572,7 @@ void InnerWidget::fill() {
|
|||
const auto inner = this;
|
||||
const auto descriptor = Descriptor{
|
||||
_peer,
|
||||
lifetime().make_state<Api::Statistics>(&_peer->session().api()),
|
||||
lifetime().make_state<Api::Statistics>(_peer->asChannel()),
|
||||
_controller->uiShow()->toastParent(),
|
||||
};
|
||||
if (_state.stats.message) {
|
||||
|
|
|
@ -47,6 +47,7 @@ constexpr auto kUpdaterDcShift = 0x03;
|
|||
constexpr auto kExportDcShift = 0x04;
|
||||
constexpr auto kExportMediaDcShift = 0x05;
|
||||
constexpr auto kGroupCallStreamDcShift = 0x06;
|
||||
constexpr auto kStatsDcShift = 0x06;
|
||||
constexpr auto kMaxMediaDcCount = 0x10;
|
||||
constexpr auto kBaseDownloadDcShift = 0x10;
|
||||
constexpr auto kBaseUploadDcShift = 0x20;
|
||||
|
|
Loading…
Add table
Reference in a new issue