Added initial ability to open statistics for single message.
This commit is contained in:
parent
01821cd779
commit
393c23ad12
|
@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "data/data_peer.h"
|
#include "data/data_peer.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
|
#include "history/history_item.h"
|
||||||
#include "info/info_controller.h"
|
#include "info/info_controller.h"
|
||||||
#include "info/info_memento.h"
|
#include "info/info_memento.h"
|
||||||
#include "info/statistics/info_statistics_recent_message.h"
|
#include "info/statistics/info_statistics_recent_message.h"
|
||||||
|
@ -24,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/layers/generic_box.h"
|
#include "ui/layers/generic_box.h"
|
||||||
#include "ui/rect.h"
|
#include "ui/rect.h"
|
||||||
#include "ui/toast/toast.h"
|
#include "ui/toast/toast.h"
|
||||||
|
#include "ui/widgets/buttons.h"
|
||||||
#include "ui/widgets/scroll_area.h"
|
#include "ui/widgets/scroll_area.h"
|
||||||
#include "ui/wrap/slide_wrap.h"
|
#include "ui/wrap/slide_wrap.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
|
@ -42,6 +44,7 @@ struct Descriptor final {
|
||||||
struct AnyStats final {
|
struct AnyStats final {
|
||||||
Data::ChannelStatistics channel;
|
Data::ChannelStatistics channel;
|
||||||
Data::SupergroupStatistics supergroup;
|
Data::SupergroupStatistics supergroup;
|
||||||
|
Data::StatisticalGraph message;
|
||||||
};
|
};
|
||||||
|
|
||||||
void ProcessZoom(
|
void ProcessZoom(
|
||||||
|
@ -207,6 +210,11 @@ void FillStatistic(
|
||||||
// s.weekGraph,
|
// s.weekGraph,
|
||||||
// tr::lng_chart_title_group_week(),
|
// tr::lng_chart_title_group_week(),
|
||||||
// Type::StackLinear);
|
// Type::StackLinear);
|
||||||
|
} else if (const auto graph = stats.message; graph.chart) {
|
||||||
|
addChart(
|
||||||
|
graph,
|
||||||
|
tr::lng_chart_title_message_interaction(),
|
||||||
|
Type::DoubleLinear);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,8 +443,9 @@ void FillOverview(
|
||||||
|
|
||||||
void FillRecentPosts(
|
void FillRecentPosts(
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
not_null<PeerData*> peer,
|
const Descriptor &descriptor,
|
||||||
const Data::ChannelStatistics &stats) {
|
const Data::ChannelStatistics &stats,
|
||||||
|
Fn<void(std::shared_ptr<Window::SectionMemento>)> showSection) {
|
||||||
const auto wrap = container->add(
|
const auto wrap = container->add(
|
||||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||||
container,
|
container,
|
||||||
|
@ -450,13 +459,25 @@ void FillRecentPosts(
|
||||||
not_null<Ui::VerticalLayout*> messageWrap,
|
not_null<Ui::VerticalLayout*> messageWrap,
|
||||||
not_null<HistoryItem*> item,
|
not_null<HistoryItem*> item,
|
||||||
const Data::StatisticsMessageInteractionInfo &info) {
|
const Data::StatisticsMessageInteractionInfo &info) {
|
||||||
const auto row = messageWrap->add(
|
const auto button = ::Settings::AddButton(
|
||||||
object_ptr<MessagePreview>(
|
messageWrap,
|
||||||
messageWrap,
|
nullptr,
|
||||||
item,
|
st::settingsButton);
|
||||||
info.viewsCount,
|
const auto raw = Ui::CreateChild<MessagePreview>(
|
||||||
info.forwardsCount),
|
button.get(),
|
||||||
st::boxRowPadding);
|
item,
|
||||||
|
info.viewsCount,
|
||||||
|
info.forwardsCount);
|
||||||
|
raw->show();
|
||||||
|
button->sizeValue(
|
||||||
|
) | rpl::start_with_next([=](const QSize &s) {
|
||||||
|
if (!s.isNull()) {
|
||||||
|
raw->setGeometry(Rect(s) - st::boxRowPadding);
|
||||||
|
}
|
||||||
|
}, raw->lifetime());
|
||||||
|
button->setClickedCallback([=, fullId = item->fullId()] {
|
||||||
|
showSection(Info::Statistics::Make(descriptor.peer, fullId));
|
||||||
|
});
|
||||||
::Settings::AddSkip(messageWrap);
|
::Settings::AddSkip(messageWrap);
|
||||||
content->resizeToWidth(content->width());
|
content->resizeToWidth(content->width());
|
||||||
if (!wrap->toggled()) {
|
if (!wrap->toggled()) {
|
||||||
|
@ -464,6 +485,7 @@ void FillRecentPosts(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const auto &peer = descriptor.peer;
|
||||||
for (const auto &recent : stats.recentMessageInteractions) {
|
for (const auto &recent : stats.recentMessageInteractions) {
|
||||||
const auto messageWrap = content->add(
|
const auto messageWrap = content->add(
|
||||||
object_ptr<Ui::VerticalLayout>(content));
|
object_ptr<Ui::VerticalLayout>(content));
|
||||||
|
@ -513,16 +535,13 @@ Widget::Widget(
|
||||||
not_null<Controller*> controller)
|
not_null<Controller*> controller)
|
||||||
: ContentWidget(parent, controller) {
|
: ContentWidget(parent, controller) {
|
||||||
const auto peer = controller->statisticsPeer();
|
const auto peer = controller->statisticsPeer();
|
||||||
|
const auto contextId = controller->statisticsContextId();
|
||||||
if (!peer) {
|
if (!peer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto inner = setInnerWidget(object_ptr<Ui::VerticalLayout>(this));
|
const auto inner = setInnerWidget(object_ptr<Ui::VerticalLayout>(this));
|
||||||
auto &lifetime = inner->lifetime();
|
auto &lifetime = inner->lifetime();
|
||||||
const auto loaded = lifetime.make_state<rpl::event_stream<bool>>();
|
const auto loaded = lifetime.make_state<rpl::event_stream<bool>>();
|
||||||
FillLoading(
|
|
||||||
inner,
|
|
||||||
loaded->events_starting_with(false) | rpl::map(!rpl::mappers::_1),
|
|
||||||
_showFinished.events());
|
|
||||||
|
|
||||||
const auto descriptor = Descriptor{
|
const auto descriptor = Descriptor{
|
||||||
peer,
|
peer,
|
||||||
|
@ -530,27 +549,55 @@ Widget::Widget(
|
||||||
controller->uiShow()->toastParent(),
|
controller->uiShow()->toastParent(),
|
||||||
};
|
};
|
||||||
|
|
||||||
_showFinished.events(
|
FillLoading(
|
||||||
) | rpl::take(1) | rpl::start_with_next([=] {
|
inner,
|
||||||
descriptor.api->request(
|
loaded->events_starting_with(false) | rpl::map(!rpl::mappers::_1),
|
||||||
descriptor.peer
|
_showFinished.events());
|
||||||
) | rpl::start_with_done([=] {
|
|
||||||
const auto anyStats = AnyStats{
|
const auto applyStats = [=](const AnyStats &anyStats) {
|
||||||
descriptor.api->channelStats(),
|
const auto isMessage = !anyStats.message.chart.empty();
|
||||||
descriptor.api->supergroupStats(),
|
if (!anyStats.channel && !anyStats.supergroup && !isMessage) {
|
||||||
};
|
return;
|
||||||
if (!anyStats.channel && !anyStats.supergroup) {
|
}
|
||||||
return;
|
if (!isMessage) {
|
||||||
}
|
|
||||||
FillOverview(inner, anyStats);
|
FillOverview(inner, anyStats);
|
||||||
FillStatistic(inner, descriptor, anyStats);
|
FillStatistic(inner, descriptor, anyStats);
|
||||||
if (anyStats.channel) {
|
if (const auto channel = anyStats.channel) {
|
||||||
FillRecentPosts(inner, descriptor.peer, anyStats.channel);
|
const auto showSection = [controller](
|
||||||
|
std::shared_ptr<Window::SectionMemento> memento) {
|
||||||
|
controller->showSection(std::move(memento));
|
||||||
|
};
|
||||||
|
FillRecentPosts(inner, descriptor, channel, showSection);
|
||||||
}
|
}
|
||||||
loaded->fire(true);
|
} else {
|
||||||
inner->resizeToWidth(width());
|
FillStatistic(inner, descriptor, anyStats);
|
||||||
inner->showChildren();
|
}
|
||||||
}, inner->lifetime());
|
loaded->fire(true);
|
||||||
|
inner->resizeToWidth(width());
|
||||||
|
inner->showChildren();
|
||||||
|
};
|
||||||
|
|
||||||
|
_showFinished.events(
|
||||||
|
) | rpl::take(1) | rpl::start_with_next([=] {
|
||||||
|
if (!contextId) {
|
||||||
|
descriptor.api->request(
|
||||||
|
descriptor.peer
|
||||||
|
) | rpl::start_with_done([=] {
|
||||||
|
applyStats({
|
||||||
|
descriptor.api->channelStats(),
|
||||||
|
descriptor.api->supergroupStats(),
|
||||||
|
});
|
||||||
|
}, inner->lifetime());
|
||||||
|
} else {
|
||||||
|
descriptor.api->requestMessage(
|
||||||
|
descriptor.peer,
|
||||||
|
contextId.msg
|
||||||
|
) | rpl::take(
|
||||||
|
1
|
||||||
|
) | rpl::start_with_next([=](const Data::StatisticalGraph &data) {
|
||||||
|
applyStats({ .message = data });
|
||||||
|
}, inner->lifetime());
|
||||||
|
}
|
||||||
}, lifetime);
|
}, lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user