mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Added ability to restore first public forwards in statistical info.
This commit is contained in:
parent
a3d8db4ac0
commit
2dc45ac907
7 changed files with 36 additions and 42 deletions
|
@ -298,8 +298,8 @@ PublicForwards::PublicForwards(
|
|||
}
|
||||
|
||||
void PublicForwards::request(
|
||||
const OffsetToken &token,
|
||||
Fn<void(Slice)> done) {
|
||||
const Data::PublicForwardsSlice::OffsetToken &token,
|
||||
Fn<void(Data::PublicForwardsSlice)> done) {
|
||||
if (_requestId) {
|
||||
return;
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ void PublicForwards::request(
|
|||
using Messages = QVector<FullMsgId>;
|
||||
_requestId = 0;
|
||||
|
||||
auto nextToken = OffsetToken();
|
||||
auto nextToken = Data::PublicForwardsSlice::OffsetToken();
|
||||
const auto process = [&](const MTPVector<MTPMessage> &messages) {
|
||||
auto result = Messages();
|
||||
for (const auto &message : messages.v) {
|
||||
|
@ -397,7 +397,7 @@ MessageStatistics::MessageStatistics(
|
|||
, _api(&channel->session().api().instance()) {
|
||||
}
|
||||
|
||||
PublicForwards::Slice MessageStatistics::firstSlice() const {
|
||||
Data::PublicForwardsSlice MessageStatistics::firstSlice() const {
|
||||
return _firstSlice;
|
||||
}
|
||||
|
||||
|
@ -409,7 +409,7 @@ void MessageStatistics::request(Fn<void(Data::MessageStatistics)> done) {
|
|||
const auto requestFirstPublicForwards = [=](
|
||||
const Data::StatisticalGraph &messageGraph,
|
||||
const Data::StatisticsMessageInteractionInfo &info) {
|
||||
_publicForwards.request({}, [=](PublicForwards::Slice slice) {
|
||||
_publicForwards.request({}, [=](Data::PublicForwardsSlice slice) {
|
||||
const auto total = slice.total;
|
||||
_firstSlice = std::move(slice);
|
||||
done({
|
||||
|
|
|
@ -43,21 +43,11 @@ private:
|
|||
|
||||
class PublicForwards final {
|
||||
public:
|
||||
struct OffsetToken final {
|
||||
int rate = 0;
|
||||
FullMsgId fullId;
|
||||
};
|
||||
|
||||
struct Slice {
|
||||
QVector<FullMsgId> list;
|
||||
int total = 0;
|
||||
bool allLoaded = false;
|
||||
OffsetToken token;
|
||||
};
|
||||
|
||||
explicit PublicForwards(not_null<ChannelData*> channel, FullMsgId fullId);
|
||||
|
||||
void request(const OffsetToken &token, Fn<void(Slice)> done);
|
||||
void request(
|
||||
const Data::PublicForwardsSlice::OffsetToken &token,
|
||||
Fn<void(Data::PublicForwardsSlice)> done);
|
||||
|
||||
private:
|
||||
const not_null<ChannelData*> _channel;
|
||||
|
@ -77,14 +67,14 @@ public:
|
|||
|
||||
void request(Fn<void(Data::MessageStatistics)> done);
|
||||
|
||||
[[nodiscard]] PublicForwards::Slice firstSlice() const;
|
||||
[[nodiscard]] Data::PublicForwardsSlice firstSlice() const;
|
||||
|
||||
private:
|
||||
PublicForwards _publicForwards;
|
||||
const not_null<ChannelData*> _channel;
|
||||
const FullMsgId _fullId;
|
||||
|
||||
PublicForwards::Slice _firstSlice;
|
||||
Data::PublicForwardsSlice _firstSlice;
|
||||
|
||||
mtpRequestId _requestId = 0;
|
||||
MTP::Sender _api;
|
||||
|
|
|
@ -119,4 +119,15 @@ struct AnyStatistics final {
|
|||
Data::MessageStatistics message;
|
||||
};
|
||||
|
||||
struct PublicForwardsSlice final {
|
||||
struct OffsetToken final {
|
||||
int rate = 0;
|
||||
FullMsgId fullId;
|
||||
};
|
||||
QVector<FullMsgId> list;
|
||||
int total = 0;
|
||||
bool allLoaded = false;
|
||||
OffsetToken token;
|
||||
};
|
||||
|
||||
} // namespace Data
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace Info::Statistics {
|
|||
struct SavedState final {
|
||||
Data::AnyStatistics stats;
|
||||
base::flat_map<MsgId, QImage> recentPostPreviews;
|
||||
Data::PublicForwardsSlice publicForwardsFirstSlice;
|
||||
};
|
||||
|
||||
} // namespace Info::Statistics
|
||||
|
|
|
@ -525,6 +525,7 @@ void InnerWidget::load() {
|
|||
|
||||
api->request([=](const Data::MessageStatistics &data) {
|
||||
_state.stats = Data::AnyStatistics{ .message = data };
|
||||
_state.publicForwardsFirstSlice = api->firstSlice();
|
||||
fill();
|
||||
|
||||
finishLoading();
|
||||
|
@ -587,16 +588,10 @@ void InnerWidget::fill() {
|
|||
tr::lng_stats_inviters_title());
|
||||
}
|
||||
} else if (message) {
|
||||
auto showPeerHistory = [=](FullMsgId fullId) {
|
||||
_showRequests.fire({ .history = fullId });
|
||||
};
|
||||
const auto api = lifetime().make_state<Api::MessageStatistics>(
|
||||
descriptor.peer->asChannel(),
|
||||
_contextId);
|
||||
AddPublicForwards(
|
||||
*api,
|
||||
_state.publicForwardsFirstSlice,
|
||||
inner,
|
||||
std::move(showPeerHistory),
|
||||
[=](FullMsgId id) { _showRequests.fire({ .history = id }); },
|
||||
descriptor.peer,
|
||||
_contextId);
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ void AddSubsectionTitle(
|
|||
}
|
||||
|
||||
struct Descriptor final {
|
||||
Api::PublicForwards::Slice firstSlice;
|
||||
Data::PublicForwardsSlice firstSlice;
|
||||
Fn<void(FullMsgId)> showPeerHistory;
|
||||
not_null<PeerData*> peer;
|
||||
FullMsgId contextId;
|
||||
|
@ -199,14 +199,14 @@ public:
|
|||
|
||||
private:
|
||||
bool appendRow(not_null<PeerData*> peer, MsgId msgId);
|
||||
void applySlice(const Api::PublicForwards::Slice &slice);
|
||||
void applySlice(const Data::PublicForwardsSlice &slice);
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
Fn<void(FullMsgId)> _showPeerHistory;
|
||||
|
||||
Api::PublicForwards _api;
|
||||
Api::PublicForwards::Slice _firstSlice;
|
||||
Api::PublicForwards::OffsetToken _apiToken;
|
||||
Data::PublicForwardsSlice _firstSlice;
|
||||
Data::PublicForwardsSlice::OffsetToken _apiToken;
|
||||
|
||||
bool _allLoaded = false;
|
||||
|
||||
|
@ -232,13 +232,13 @@ void PublicForwardsController::loadMoreRows() {
|
|||
if (_allLoaded) {
|
||||
return;
|
||||
}
|
||||
_api.request(_apiToken, [=](const Api::PublicForwards::Slice &slice) {
|
||||
_api.request(_apiToken, [=](const Data::PublicForwardsSlice &slice) {
|
||||
applySlice(slice);
|
||||
});
|
||||
}
|
||||
|
||||
void PublicForwardsController::applySlice(
|
||||
const Api::PublicForwards::Slice &slice) {
|
||||
const Data::PublicForwardsSlice &slice) {
|
||||
_allLoaded = slice.allLoaded;
|
||||
_apiToken = slice.token;
|
||||
|
||||
|
@ -291,7 +291,7 @@ bool PublicForwardsController::appendRow(
|
|||
} // namespace
|
||||
|
||||
void AddPublicForwards(
|
||||
const Api::MessageStatistics &firstSliceHolder,
|
||||
const Data::PublicForwardsSlice &firstSlice,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
Fn<void(FullMsgId)> showPeerHistory,
|
||||
not_null<PeerData*> peer,
|
||||
|
@ -307,13 +307,13 @@ void AddPublicForwards(
|
|||
PublicForwardsController controller;
|
||||
};
|
||||
const auto state = container->lifetime().make_state<State>(Descriptor{
|
||||
firstSliceHolder.firstSlice(),
|
||||
firstSlice,
|
||||
std::move(showPeerHistory),
|
||||
peer,
|
||||
contextId,
|
||||
});
|
||||
|
||||
if (const auto total = firstSliceHolder.firstSlice().total; total > 0) {
|
||||
if (const auto total = firstSlice.total; total > 0) {
|
||||
AddSubsectionTitle(
|
||||
container,
|
||||
tr::lng_stats_overview_message_public_share(
|
||||
|
|
|
@ -13,18 +13,15 @@ namespace Ui {
|
|||
class VerticalLayout;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Api {
|
||||
class MessageStatistics;
|
||||
} // namespace Api
|
||||
|
||||
namespace Data {
|
||||
struct PublicForwardsSlice;
|
||||
struct SupergroupStatistics;
|
||||
} // namespace Data
|
||||
|
||||
namespace Info::Statistics {
|
||||
|
||||
void AddPublicForwards(
|
||||
const Api::MessageStatistics &firstSliceHolder,
|
||||
const Data::PublicForwardsSlice &firstSlice,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
Fn<void(FullMsgId)> showPeerHistory,
|
||||
not_null<PeerData*> peer,
|
||||
|
|
Loading…
Add table
Reference in a new issue