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