mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 15:43:55 +02:00
Slightly refactored code for info of statistic for single message.
This commit is contained in:
parent
3fa168cee0
commit
a79e025151
3 changed files with 76 additions and 121 deletions
|
@ -21,6 +21,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
namespace Info::Statistics {
|
namespace Info::Statistics {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
struct Descriptor final {
|
||||||
|
Api::PublicForwards::Slice firstSlice;
|
||||||
|
Fn<void(FullMsgId)> showPeerHistory;
|
||||||
|
not_null<PeerData*> peer;
|
||||||
|
FullMsgId contextId;
|
||||||
|
};
|
||||||
|
|
||||||
class PeerListRowWithMsgId : public PeerListRow {
|
class PeerListRowWithMsgId : public PeerListRow {
|
||||||
public:
|
public:
|
||||||
using PeerListRow::PeerListRow;
|
using PeerListRow::PeerListRow;
|
||||||
|
@ -43,10 +50,7 @@ MsgId PeerListRowWithMsgId::msgId() const {
|
||||||
|
|
||||||
class PublicForwardsController final : public PeerListController {
|
class PublicForwardsController final : public PeerListController {
|
||||||
public:
|
public:
|
||||||
explicit PublicForwardsController(
|
explicit PublicForwardsController(Descriptor d);
|
||||||
Fn<void(FullMsgId)> showPeerHistory,
|
|
||||||
not_null<PeerData*> peer,
|
|
||||||
FullMsgId contextId);
|
|
||||||
|
|
||||||
Main::Session &session() const override;
|
Main::Session &session() const override;
|
||||||
void prepare() override;
|
void prepare() override;
|
||||||
|
@ -57,11 +61,13 @@ 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);
|
||||||
|
|
||||||
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;
|
||||||
Api::PublicForwards::OffsetToken _apiToken;
|
Api::PublicForwards::OffsetToken _apiToken;
|
||||||
|
|
||||||
bool _allLoaded = false;
|
bool _allLoaded = false;
|
||||||
|
@ -70,13 +76,11 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PublicForwardsController::PublicForwardsController(
|
PublicForwardsController::PublicForwardsController(Descriptor d)
|
||||||
Fn<void(FullMsgId)> showPeerHistory,
|
: _session(&d.peer->session())
|
||||||
not_null<PeerData*> peer,
|
, _showPeerHistory(std::move(d.showPeerHistory))
|
||||||
FullMsgId contextId)
|
, _api(d.peer->asChannel(), d.contextId)
|
||||||
: _session(&peer->session())
|
, _firstSlice(std::move(d.firstSlice)) {
|
||||||
, _showPeerHistory(std::move(showPeerHistory))
|
|
||||||
, _api(peer->asChannel(), contextId) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Main::Session &PublicForwardsController::session() const {
|
Main::Session &PublicForwardsController::session() const {
|
||||||
|
@ -84,7 +88,7 @@ Main::Session &PublicForwardsController::session() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PublicForwardsController::prepare() {
|
void PublicForwardsController::prepare() {
|
||||||
loadMoreRows();
|
applySlice(base::take(_firstSlice));
|
||||||
delegate()->peerListRefreshRows();
|
delegate()->peerListRefreshRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +97,12 @@ void PublicForwardsController::loadMoreRows() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_api.request(_apiToken, [=](const Api::PublicForwards::Slice &slice) {
|
_api.request(_apiToken, [=](const Api::PublicForwards::Slice &slice) {
|
||||||
|
applySlice(slice);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void PublicForwardsController::applySlice(
|
||||||
|
const Api::PublicForwards::Slice &slice) {
|
||||||
_allLoaded = slice.allLoaded;
|
_allLoaded = slice.allLoaded;
|
||||||
_apiToken = slice.token;
|
_apiToken = slice.token;
|
||||||
_totalCountChanges.fire_copy(slice.total);
|
_totalCountChanges.fire_copy(slice.total);
|
||||||
|
@ -103,7 +113,6 @@ void PublicForwardsController::loadMoreRows() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delegate()->peerListRefreshRows();
|
delegate()->peerListRefreshRows();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PublicForwardsController::rowClicked(not_null<PeerListRow*> row) {
|
void PublicForwardsController::rowClicked(not_null<PeerListRow*> row) {
|
||||||
|
@ -150,53 +159,42 @@ rpl::producer<int> PublicForwardsController::totalCountChanges() const {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
PublicShares AddPublicForwards(
|
void AddPublicForwards(
|
||||||
|
const Api::MessageStatistics &firstSliceHolder,
|
||||||
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,
|
||||||
FullMsgId contextId) {
|
FullMsgId contextId) {
|
||||||
if (!peer->isChannel()) {
|
if (!peer->isChannel()) {
|
||||||
return rpl::never<int>();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct State final {
|
struct State final {
|
||||||
State(
|
State(Descriptor d) : controller(std::move(d)) {
|
||||||
Fn<void(FullMsgId)> c,
|
|
||||||
not_null<PeerData*> p,
|
|
||||||
FullMsgId i) : controller(std::move(c), p, i) {
|
|
||||||
}
|
}
|
||||||
PeerListContentDelegateSimple delegate;
|
PeerListContentDelegateSimple delegate;
|
||||||
PublicForwardsController controller;
|
PublicForwardsController controller;
|
||||||
};
|
};
|
||||||
const auto state = container->lifetime().make_state<State>(
|
const auto state = container->lifetime().make_state<State>(Descriptor{
|
||||||
|
firstSliceHolder.firstSlice(),
|
||||||
std::move(showPeerHistory),
|
std::move(showPeerHistory),
|
||||||
peer,
|
peer,
|
||||||
contextId);
|
contextId,
|
||||||
|
|
||||||
auto title = state->controller.totalCountChanges(
|
|
||||||
) | rpl::distinct_until_changed(
|
|
||||||
) | rpl::map([=](int total) {
|
|
||||||
return total
|
|
||||||
? tr::lng_stats_overview_message_public_share(
|
|
||||||
tr::now,
|
|
||||||
lt_count_decimal,
|
|
||||||
total)
|
|
||||||
: QString();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
if (const auto total = firstSliceHolder.firstSlice().total; total > 0) {
|
||||||
const auto &subtitlePadding = st::settingsButton.padding;
|
const auto &subtitlePadding = st::settingsButton.padding;
|
||||||
::Settings::AddSubsectionTitle(
|
::Settings::AddSubsectionTitle(
|
||||||
container,
|
container,
|
||||||
std::move(title),
|
tr::lng_stats_overview_message_public_share(
|
||||||
|
lt_count_decimal,
|
||||||
|
rpl::single<float64>(total)),
|
||||||
{ 0, -subtitlePadding.top(), 0, -subtitlePadding.bottom() });
|
{ 0, -subtitlePadding.top(), 0, -subtitlePadding.bottom() });
|
||||||
}
|
}
|
||||||
|
|
||||||
state->delegate.setContent(container->add(
|
state->delegate.setContent(container->add(
|
||||||
object_ptr<PeerListContent>(container, &state->controller)));
|
object_ptr<PeerListContent>(container, &state->controller)));
|
||||||
state->controller.setDelegate(&state->delegate);
|
state->controller.setDelegate(&state->delegate);
|
||||||
|
|
||||||
return state->controller.totalCountChanges(
|
|
||||||
) | rpl::distinct_until_changed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Info::Statistics
|
} // namespace Info::Statistics
|
||||||
|
|
|
@ -13,11 +13,14 @@ namespace Ui {
|
||||||
class VerticalLayout;
|
class VerticalLayout;
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
||||||
|
namespace Api {
|
||||||
|
class MessageStatistics;
|
||||||
|
} // namespace Api
|
||||||
|
|
||||||
namespace Info::Statistics {
|
namespace Info::Statistics {
|
||||||
|
|
||||||
using PublicShares = rpl::producer<int>;
|
void AddPublicForwards(
|
||||||
|
const Api::MessageStatistics &firstSliceHolder,
|
||||||
[[nodiscard]] PublicShares AddPublicForwards(
|
|
||||||
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,
|
||||||
|
|
|
@ -45,15 +45,7 @@ struct Descriptor final {
|
||||||
struct AnyStats final {
|
struct AnyStats final {
|
||||||
Data::ChannelStatistics channel;
|
Data::ChannelStatistics channel;
|
||||||
Data::SupergroupStatistics supergroup;
|
Data::SupergroupStatistics supergroup;
|
||||||
struct Message {
|
Data::MessageStatistics message;
|
||||||
explicit operator bool() const {
|
|
||||||
return !graph.chart.empty();
|
|
||||||
}
|
|
||||||
Data::StatisticalGraph graph;
|
|
||||||
int publicForwards = 0;
|
|
||||||
int privateForwards = 0;
|
|
||||||
int views = 0;
|
|
||||||
} message;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void ProcessZoom(
|
void ProcessZoom(
|
||||||
|
@ -221,7 +213,7 @@ void FillStatistic(
|
||||||
// Type::StackLinear);
|
// Type::StackLinear);
|
||||||
} else if (const auto message = stats.message) {
|
} else if (const auto message = stats.message) {
|
||||||
addChart(
|
addChart(
|
||||||
message.graph,
|
message.messageInteractionGraph,
|
||||||
tr::lng_chart_title_message_interaction(),
|
tr::lng_chart_title_message_interaction(),
|
||||||
Type::DoubleLinear);
|
Type::DoubleLinear);
|
||||||
}
|
}
|
||||||
|
@ -628,37 +620,16 @@ Widget::Widget(
|
||||||
}, inner->lifetime());
|
}, inner->lifetime());
|
||||||
} else {
|
} else {
|
||||||
const auto weak = base::make_weak(controller);
|
const auto weak = base::make_weak(controller);
|
||||||
|
const auto lifetime = inner->lifetime(
|
||||||
|
).make_state<rpl::lifetime>();
|
||||||
|
const auto api = lifetime->make_state<Api::MessageStatistics>(
|
||||||
|
descriptor.peer->asChannel(),
|
||||||
|
contextId);
|
||||||
|
|
||||||
descriptor.api->requestMessage(
|
api->request([=](const Data::MessageStatistics &data) {
|
||||||
descriptor.peer,
|
const auto stats = AnyStats{ .message = data };
|
||||||
contextId.msg
|
FillOverview(inner, stats);
|
||||||
) | rpl::take(
|
FillStatistic(inner, descriptor, stats);
|
||||||
1
|
|
||||||
) | rpl::start_with_next([=](const Data::StatisticalGraph &data) {
|
|
||||||
descriptor.api->request(
|
|
||||||
descriptor.peer
|
|
||||||
) | rpl::start_with_done([=] {
|
|
||||||
const auto channel = descriptor.api->channelStats();
|
|
||||||
auto info = Data::StatisticsMessageInteractionInfo();
|
|
||||||
for (const auto &r : channel.recentMessageInteractions) {
|
|
||||||
if (r.messageId == contextId.msg) {
|
|
||||||
info = r;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto wrapAbove = inner->add(
|
|
||||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
||||||
inner,
|
|
||||||
object_ptr<Ui::VerticalLayout>(inner)));
|
|
||||||
wrapAbove->toggle(false, anim::type::instant);
|
|
||||||
|
|
||||||
const auto wrapBelow = inner->add(
|
|
||||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
||||||
inner,
|
|
||||||
object_ptr<Ui::VerticalLayout>(inner)));
|
|
||||||
wrapBelow->toggle(false, anim::type::instant);
|
|
||||||
|
|
||||||
auto showPeerHistory = [=](FullMsgId fullId) {
|
auto showPeerHistory = [=](FullMsgId fullId) {
|
||||||
if (const auto strong = weak.get()) {
|
if (const auto strong = weak.get()) {
|
||||||
controller->showPeerHistory(
|
controller->showPeerHistory(
|
||||||
|
@ -667,33 +638,16 @@ Widget::Widget(
|
||||||
fullId.msg);
|
fullId.msg);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
auto sharesCount = AddPublicForwards(
|
AddPublicForwards(
|
||||||
wrapBelow->entity(),
|
*api,
|
||||||
|
inner,
|
||||||
std::move(showPeerHistory),
|
std::move(showPeerHistory),
|
||||||
descriptor.peer,
|
descriptor.peer,
|
||||||
contextId);
|
contextId);
|
||||||
|
|
||||||
std::move(sharesCount) | rpl::take(
|
|
||||||
1
|
|
||||||
) | rpl::start_with_next([=](int count) {
|
|
||||||
const auto stats = AnyStats{
|
|
||||||
.message = {
|
|
||||||
.graph = data,
|
|
||||||
.publicForwards = count,
|
|
||||||
.privateForwards = info.forwardsCount - count,
|
|
||||||
.views = info.viewsCount,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
FillOverview(wrapAbove->entity(), stats);
|
|
||||||
FillStatistic(wrapAbove->entity(), descriptor, stats);
|
|
||||||
|
|
||||||
wrapAbove->toggle(true, anim::type::instant);
|
|
||||||
wrapBelow->toggle(true, anim::type::instant);
|
|
||||||
|
|
||||||
finishLoading();
|
finishLoading();
|
||||||
}, inner->lifetime());
|
lifetime->destroy();
|
||||||
}, inner->lifetime());
|
});
|
||||||
}, inner->lifetime());
|
|
||||||
}
|
}
|
||||||
}, lifetime);
|
}, lifetime);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue