init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "data/data_statistics.h"
|
||||
|
||||
namespace Info::Statistics {
|
||||
|
||||
struct SavedState final {
|
||||
Data::AnyStatistics stats;
|
||||
base::flat_map<Data::RecentPostId, QImage> recentPostPreviews;
|
||||
Data::PublicForwardsSlice publicForwardsFirstSlice;
|
||||
int recentPostsExpanded = 0;
|
||||
};
|
||||
|
||||
} // namespace Info::Statistics
|
||||
@@ -0,0 +1,959 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "info/statistics/info_statistics_inner_widget.h"
|
||||
|
||||
#include "api/api_statistics.h"
|
||||
#include "apiwrap.h"
|
||||
#include "base/call_delayed.h"
|
||||
#include "base/event_filter.h"
|
||||
#include "data/data_peer.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_stories.h"
|
||||
#include "data/data_story.h"
|
||||
#include "history/history_item.h"
|
||||
#include "info/info_controller.h"
|
||||
#include "info/info_memento.h"
|
||||
#include "info/statistics/info_statistics_list_controllers.h"
|
||||
#include "info/statistics/info_statistics_recent_message.h"
|
||||
#include "info/statistics/info_statistics_widget.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "lottie/lottie_icon.h"
|
||||
#include "main/main_session.h"
|
||||
#include "settings/settings_common.h" // CreateLottieIcon.
|
||||
#include "statistics/chart_widget.h"
|
||||
#include "statistics/statistics_common.h"
|
||||
#include "statistics/statistics_format_values.h"
|
||||
#include "statistics/widgets/chart_header_widget.h"
|
||||
#include "ui/layers/generic_box.h"
|
||||
#include "ui/rect.h"
|
||||
#include "ui/vertical_list.h"
|
||||
#include "ui/toast/toast.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/popup_menu.h"
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_menu_icons.h"
|
||||
#include "styles/style_settings.h"
|
||||
#include "styles/style_statistics.h"
|
||||
|
||||
namespace Info::Statistics {
|
||||
namespace {
|
||||
|
||||
struct Descriptor final {
|
||||
not_null<PeerData*> peer;
|
||||
not_null<Api::Statistics*> api;
|
||||
not_null<QWidget*> toastParent;
|
||||
};
|
||||
|
||||
void AddContextMenu(
|
||||
not_null<Ui::RpWidget*> button,
|
||||
not_null<Controller*> controller,
|
||||
not_null<HistoryItem*> item) {
|
||||
const auto fullId = item->fullId();
|
||||
const auto contextMenu = button->lifetime()
|
||||
.make_state<base::unique_qptr<Ui::PopupMenu>>();
|
||||
const auto showMenu = [=] {
|
||||
*contextMenu = base::make_unique_q<Ui::PopupMenu>(
|
||||
button,
|
||||
st::popupMenuWithIcons);
|
||||
const auto go = [=] {
|
||||
const auto &session = controller->parentController();
|
||||
if (const auto item = session->session().data().message(fullId)) {
|
||||
session->showMessage(item);
|
||||
}
|
||||
};
|
||||
contextMenu->get()->addAction(
|
||||
tr::lng_context_to_msg(tr::now),
|
||||
crl::guard(controller, go),
|
||||
&st::menuIconShowInChat);
|
||||
contextMenu->get()->popup(QCursor::pos());
|
||||
};
|
||||
|
||||
base::install_event_filter(button, [=](not_null<QEvent*> e) {
|
||||
if (e->type() == QEvent::ContextMenu) {
|
||||
showMenu();
|
||||
return base::EventFilterResult::Cancel;
|
||||
}
|
||||
return base::EventFilterResult::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
void ProcessZoom(
|
||||
const Descriptor &d,
|
||||
not_null<Statistic::ChartWidget*> widget,
|
||||
const QString &zoomToken,
|
||||
Statistic::ChartViewType type) {
|
||||
if (zoomToken.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
widget->zoomRequests(
|
||||
) | rpl::on_next([=](float64 x) {
|
||||
d.api->requestZoom(
|
||||
zoomToken,
|
||||
x
|
||||
) | rpl::on_next_error_done([=](
|
||||
const Data::StatisticalGraph &graph) {
|
||||
if (graph.chart) {
|
||||
widget->setZoomedChartData(graph.chart, x, type);
|
||||
} else if (!graph.error.isEmpty()) {
|
||||
Ui::Toast::Show(d.toastParent, graph.error);
|
||||
}
|
||||
}, [=](const QString &error) {
|
||||
}, [=] {
|
||||
}, widget->lifetime());
|
||||
}, widget->lifetime());
|
||||
}
|
||||
|
||||
void FillStatistic(
|
||||
not_null<Ui::VerticalLayout*> content,
|
||||
const Descriptor &descriptor,
|
||||
Data::AnyStatistics &stats,
|
||||
Fn<void()> done) {
|
||||
using Type = Statistic::ChartViewType;
|
||||
const auto &padding = st::statisticsChartEntryPadding;
|
||||
const auto &m = st::statisticsLayerMargins;
|
||||
const auto addSkip = [&](not_null<Ui::VerticalLayout*> c) {
|
||||
Ui::AddSkip(c, padding.bottom());
|
||||
Ui::AddDivider(c);
|
||||
Ui::AddSkip(c, padding.top());
|
||||
};
|
||||
struct State final {
|
||||
Fn<void()> done;
|
||||
int pendingCount = 0;
|
||||
};
|
||||
const auto state = content->lifetime().make_state<State>(
|
||||
State{ std::move(done) });
|
||||
|
||||
const auto singlePendingDone = [=] {
|
||||
state->pendingCount--;
|
||||
if (!state->pendingCount && state->done) {
|
||||
base::take(state->done)();
|
||||
}
|
||||
};
|
||||
|
||||
const auto addChart = [&](
|
||||
Data::StatisticalGraph &graphData,
|
||||
rpl::producer<QString> &&title,
|
||||
Statistic::ChartViewType type) {
|
||||
if (graphData.chart) {
|
||||
const auto widget = content->add(
|
||||
object_ptr<Statistic::ChartWidget>(content),
|
||||
m);
|
||||
|
||||
widget->setChartData(graphData.chart, type);
|
||||
ProcessZoom(descriptor, widget, graphData.zoomToken, type);
|
||||
widget->setTitle(std::move(title));
|
||||
|
||||
addSkip(content);
|
||||
} else if (!graphData.zoomToken.isEmpty()) {
|
||||
state->pendingCount++;
|
||||
const auto wrap = content->add(
|
||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||
content,
|
||||
object_ptr<Ui::VerticalLayout>(content)));
|
||||
wrap->toggle(false, anim::type::instant);
|
||||
const auto widget = wrap->entity()->add(
|
||||
object_ptr<Statistic::ChartWidget>(content),
|
||||
m);
|
||||
|
||||
descriptor.api->requestZoom(
|
||||
graphData.zoomToken,
|
||||
0
|
||||
) | rpl::on_next_error_done([=, graphPtr = &graphData](
|
||||
const Data::StatisticalGraph &graph) mutable {
|
||||
{
|
||||
// Save the loaded async data to cache.
|
||||
// Guarded by content->lifetime().
|
||||
*graphPtr = graph;
|
||||
}
|
||||
|
||||
if (graph.chart) {
|
||||
widget->setChartData(graph.chart, type);
|
||||
wrap->toggle(true, anim::type::instant);
|
||||
ProcessZoom(descriptor, widget, graph.zoomToken, type);
|
||||
widget->setTitle(rpl::duplicate(title));
|
||||
} else if (!graph.error.isEmpty()) {
|
||||
}
|
||||
}, [=](const QString &error) {
|
||||
singlePendingDone();
|
||||
}, [=] {
|
||||
singlePendingDone();
|
||||
}, content->lifetime());
|
||||
|
||||
addSkip(wrap->entity());
|
||||
}
|
||||
};
|
||||
addSkip(content);
|
||||
if (stats.channel) {
|
||||
addChart(
|
||||
stats.channel.memberCountGraph,
|
||||
tr::lng_chart_title_member_count(),
|
||||
Type::Linear);
|
||||
addChart(
|
||||
stats.channel.joinGraph,
|
||||
tr::lng_chart_title_join(),
|
||||
Type::Linear);
|
||||
addChart(
|
||||
stats.channel.muteGraph,
|
||||
tr::lng_chart_title_mute(),
|
||||
Type::Linear);
|
||||
addChart(
|
||||
stats.channel.viewCountByHourGraph,
|
||||
tr::lng_chart_title_view_count_by_hour(),
|
||||
Type::Linear);
|
||||
addChart(
|
||||
stats.channel.viewCountBySourceGraph,
|
||||
tr::lng_chart_title_view_count_by_source(),
|
||||
Type::StackBar);
|
||||
addChart(
|
||||
stats.channel.joinBySourceGraph,
|
||||
tr::lng_chart_title_join_by_source(),
|
||||
Type::StackBar);
|
||||
addChart(
|
||||
stats.channel.languageGraph,
|
||||
tr::lng_chart_title_language(),
|
||||
Type::StackLinear);
|
||||
addChart(
|
||||
stats.channel.messageInteractionGraph,
|
||||
tr::lng_chart_title_message_interaction(),
|
||||
Type::DoubleLinear);
|
||||
addChart(
|
||||
stats.channel.instantViewInteractionGraph,
|
||||
tr::lng_chart_title_instant_view_interaction(),
|
||||
Type::DoubleLinear);
|
||||
addChart(
|
||||
stats.channel.reactionsByEmotionGraph,
|
||||
tr::lng_chart_title_reactions_by_emotion(),
|
||||
Type::Bar);
|
||||
addChart(
|
||||
stats.channel.storyInteractionsGraph,
|
||||
tr::lng_chart_title_story_interactions(),
|
||||
Type::DoubleLinear);
|
||||
addChart(
|
||||
stats.channel.storyReactionsByEmotionGraph,
|
||||
tr::lng_chart_title_story_reactions_by_emotion(),
|
||||
Type::Bar);
|
||||
} else if (stats.supergroup) {
|
||||
addChart(
|
||||
stats.supergroup.memberCountGraph,
|
||||
tr::lng_chart_title_member_count(),
|
||||
Type::Linear);
|
||||
addChart(
|
||||
stats.supergroup.joinGraph,
|
||||
tr::lng_chart_title_group_join(),
|
||||
Type::Linear);
|
||||
addChart(
|
||||
stats.supergroup.joinBySourceGraph,
|
||||
tr::lng_chart_title_group_join_by_source(),
|
||||
Type::StackBar);
|
||||
addChart(
|
||||
stats.supergroup.languageGraph,
|
||||
tr::lng_chart_title_group_language(),
|
||||
Type::StackLinear);
|
||||
addChart(
|
||||
stats.supergroup.messageContentGraph,
|
||||
tr::lng_chart_title_group_message_content(),
|
||||
Type::StackBar);
|
||||
addChart(
|
||||
stats.supergroup.actionGraph,
|
||||
tr::lng_chart_title_group_action(),
|
||||
Type::DoubleLinear);
|
||||
addChart(
|
||||
stats.supergroup.dayGraph,
|
||||
tr::lng_chart_title_group_day(),
|
||||
Type::Linear);
|
||||
addChart(
|
||||
stats.supergroup.weekGraph,
|
||||
tr::lng_chart_title_group_week(),
|
||||
Type::StackLinear);
|
||||
} else {
|
||||
auto &messageOrStory = stats.message
|
||||
? stats.message
|
||||
: stats.story;
|
||||
if (messageOrStory) {
|
||||
addChart(
|
||||
messageOrStory.messageInteractionGraph,
|
||||
tr::lng_chart_title_message_interaction(),
|
||||
Type::DoubleLinear);
|
||||
addChart(
|
||||
messageOrStory.reactionsByEmotionGraph,
|
||||
tr::lng_chart_title_reactions_by_emotion(),
|
||||
Type::Bar);
|
||||
}
|
||||
}
|
||||
Statistic::FixCacheForHighDPIChartWidget(content);
|
||||
if (!state->pendingCount) {
|
||||
++state->pendingCount;
|
||||
singlePendingDone();
|
||||
}
|
||||
}
|
||||
|
||||
void AddHeader(
|
||||
not_null<Ui::VerticalLayout*> content,
|
||||
tr::phrase<> text,
|
||||
const Data::AnyStatistics &stats) {
|
||||
const auto startDate = stats.channel
|
||||
? stats.channel.startDate
|
||||
: stats.supergroup.startDate;
|
||||
const auto endDate = stats.channel
|
||||
? stats.channel.endDate
|
||||
: stats.supergroup.endDate;
|
||||
const auto header = content->add(
|
||||
object_ptr<Statistic::Header>(content),
|
||||
st::statisticsLayerMargins + st::statisticsChartHeaderPadding);
|
||||
header->resizeToWidth(header->width());
|
||||
header->setTitle(text(tr::now));
|
||||
if (!endDate || !startDate) {
|
||||
header->setSubTitle({});
|
||||
return;
|
||||
}
|
||||
header->setSubTitle(Statistic::LangDayMonthYear(startDate)
|
||||
+ ' '
|
||||
+ QChar(8212)
|
||||
+ ' '
|
||||
+ Statistic::LangDayMonthYear(endDate));
|
||||
}
|
||||
|
||||
void FillOverview(
|
||||
not_null<Ui::VerticalLayout*> content,
|
||||
const Data::AnyStatistics &stats,
|
||||
bool isChannelStoryStats) {
|
||||
using Value = Data::StatisticalValue;
|
||||
|
||||
const auto &channel = stats.channel;
|
||||
const auto &supergroup = stats.supergroup;
|
||||
|
||||
if (!isChannelStoryStats) {
|
||||
Ui::AddSkip(content, st::statisticsLayerOverviewMargins.top());
|
||||
AddHeader(content, tr::lng_stats_overview_title, stats);
|
||||
Ui::AddSkip(content);
|
||||
}
|
||||
|
||||
struct Second final {
|
||||
QColor color;
|
||||
QString text;
|
||||
};
|
||||
|
||||
const auto parseSecond = [&](const Value &v) -> Second {
|
||||
const auto diff = v.value - v.previousValue;
|
||||
if (!diff || !v.previousValue) {
|
||||
return {};
|
||||
}
|
||||
constexpr auto kTooMuchDiff = int(1'000'000);
|
||||
const auto diffAbs = std::abs(diff);
|
||||
const auto diffText = diffAbs > kTooMuchDiff
|
||||
? Lang::FormatCountToShort(std::abs(diff)).string
|
||||
: QString::number(diffAbs);
|
||||
const auto percentage = std::abs(v.growthRatePercentage);
|
||||
const auto precision = (percentage == int(percentage)) ? 0 : 1;
|
||||
return {
|
||||
(diff < 0 ? st::menuIconAttentionColor : st::settingsIconBg2)->c,
|
||||
QString("%1%2 (%3%)")
|
||||
.arg((diff < 0) ? QChar(0x2212) : QChar(0x002B))
|
||||
.arg(diffText)
|
||||
.arg(QString::number(percentage, 'f', precision))
|
||||
};
|
||||
};
|
||||
|
||||
const auto diffBetweenHeaders = 0
|
||||
+ st::statisticsOverviewValue.style.font->height
|
||||
- st::statisticsHeaderTitleTextStyle.font->height;
|
||||
|
||||
const auto container = content->add(
|
||||
object_ptr<Ui::RpWidget>(content),
|
||||
st::statisticsLayerMargins);
|
||||
|
||||
const auto addPrimary = [&](const Value &v) {
|
||||
return Ui::CreateChild<Ui::FlatLabel>(
|
||||
container,
|
||||
(v.value >= 0)
|
||||
? Lang::FormatCountToShort(v.value).string
|
||||
: QString(),
|
||||
st::statisticsOverviewValue);
|
||||
};
|
||||
const auto addSub = [&](
|
||||
not_null<Ui::RpWidget*> primary,
|
||||
const Value &v,
|
||||
tr::phrase<> text) {
|
||||
const auto data = parseSecond(v);
|
||||
const auto second = Ui::CreateChild<Ui::FlatLabel>(
|
||||
container,
|
||||
data.text,
|
||||
st::statisticsOverviewSecondValue);
|
||||
second->setTextColorOverride(data.color);
|
||||
const auto sub = Ui::CreateChild<Ui::FlatLabel>(
|
||||
container,
|
||||
text(),
|
||||
st::statisticsOverviewSubtext);
|
||||
sub->setTextColorOverride(st::windowSubTextFg->c);
|
||||
|
||||
primary->geometryValue(
|
||||
) | rpl::on_next([=](const QRect &g) {
|
||||
const auto &padding = st::statisticsOverviewSecondValuePadding;
|
||||
second->moveToLeft(
|
||||
rect::right(g) + padding.left(),
|
||||
g.y() + padding.top());
|
||||
sub->moveToLeft(
|
||||
g.x(),
|
||||
st::statisticsChartHeaderHeight
|
||||
- st::statisticsOverviewSubtext.style.font->height
|
||||
+ g.y()
|
||||
+ diffBetweenHeaders);
|
||||
if (container->height() < rect::bottom(sub)) {
|
||||
container->resize(container->width(), rect::bottom(sub));
|
||||
}
|
||||
}, primary->lifetime());
|
||||
};
|
||||
|
||||
const auto isChannel = (!!channel);
|
||||
const auto &messageOrStory = stats.message ? stats.message : stats.story;
|
||||
const auto isMessage = (!!messageOrStory);
|
||||
|
||||
const auto hasPostReactions = isChannel
|
||||
&& (channel.meanReactionCount.value
|
||||
|| channel.meanReactionCount.previousValue);
|
||||
|
||||
const auto topLeftLabel = (isChannelStoryStats && isChannel)
|
||||
? addPrimary(channel.meanShareCount)
|
||||
: isChannel
|
||||
? addPrimary(channel.memberCount)
|
||||
: isMessage
|
||||
? addPrimary({ .value = float64(messageOrStory.views) })
|
||||
: addPrimary(supergroup.memberCount);
|
||||
const auto topRightLabel = (isChannelStoryStats && isChannel)
|
||||
? addPrimary(channel.meanStoryShareCount)
|
||||
: isChannel
|
||||
? Ui::CreateChild<Ui::FlatLabel>(
|
||||
container,
|
||||
QString("%1%").arg(0.01
|
||||
* std::round(channel.enabledNotificationsPercentage * 100.)),
|
||||
st::statisticsOverviewValue)
|
||||
: isMessage
|
||||
? addPrimary({ .value = float64(messageOrStory.publicForwards) })
|
||||
: addPrimary(supergroup.messageCount);
|
||||
const auto bottomLeftLabel = (isChannelStoryStats && isChannel)
|
||||
? addPrimary(hasPostReactions
|
||||
? channel.meanReactionCount
|
||||
: channel.meanStoryReactionCount)
|
||||
: isChannel
|
||||
? addPrimary(channel.meanViewCount)
|
||||
: isMessage
|
||||
? addPrimary({ .value = float64(messageOrStory.reactions) })
|
||||
: addPrimary(supergroup.viewerCount);
|
||||
const auto bottomRightLabel = (isChannelStoryStats && isChannel)
|
||||
? addPrimary(!hasPostReactions
|
||||
? Value{ .value = -1 }
|
||||
: channel.meanStoryReactionCount)
|
||||
: isChannel
|
||||
? addPrimary(channel.meanStoryViewCount)
|
||||
: isMessage
|
||||
? addPrimary({ .value = float64(messageOrStory.privateForwards) })
|
||||
: addPrimary(supergroup.senderCount);
|
||||
if (isChannelStoryStats && isChannel) {
|
||||
addSub(
|
||||
topLeftLabel,
|
||||
channel.meanShareCount,
|
||||
tr::lng_stats_overview_mean_share_count);
|
||||
addSub(
|
||||
topRightLabel,
|
||||
channel.meanStoryShareCount,
|
||||
tr::lng_stats_overview_mean_story_share_count);
|
||||
addSub(
|
||||
bottomLeftLabel,
|
||||
hasPostReactions
|
||||
? channel.meanReactionCount
|
||||
: channel.meanStoryReactionCount,
|
||||
hasPostReactions
|
||||
? tr::lng_stats_overview_mean_reactions_count
|
||||
: tr::lng_stats_overview_mean_story_reactions_count);
|
||||
if (hasPostReactions) {
|
||||
addSub(
|
||||
bottomRightLabel,
|
||||
channel.meanStoryReactionCount,
|
||||
tr::lng_stats_overview_mean_story_reactions_count);
|
||||
}
|
||||
} else if (const auto &s = channel) {
|
||||
addSub(
|
||||
topLeftLabel,
|
||||
s.memberCount,
|
||||
tr::lng_stats_overview_member_count);
|
||||
addSub(
|
||||
topRightLabel,
|
||||
{},
|
||||
tr::lng_stats_overview_enabled_notifications);
|
||||
addSub(
|
||||
bottomLeftLabel,
|
||||
s.meanViewCount,
|
||||
tr::lng_stats_overview_mean_view_count);
|
||||
addSub(
|
||||
bottomRightLabel,
|
||||
s.meanStoryViewCount,
|
||||
tr::lng_stats_overview_mean_story_view_count);
|
||||
} else if (const auto &s = supergroup) {
|
||||
addSub(
|
||||
topLeftLabel,
|
||||
s.memberCount,
|
||||
tr::lng_manage_peer_members);
|
||||
addSub(
|
||||
topRightLabel,
|
||||
s.messageCount,
|
||||
tr::lng_stats_overview_messages);
|
||||
addSub(
|
||||
bottomLeftLabel,
|
||||
s.viewerCount,
|
||||
tr::lng_stats_overview_group_mean_view_count);
|
||||
addSub(
|
||||
bottomRightLabel,
|
||||
s.senderCount,
|
||||
tr::lng_stats_overview_group_mean_post_count);
|
||||
} else if (const auto &s = messageOrStory) {
|
||||
if (s.views >= 0) {
|
||||
addSub(
|
||||
topLeftLabel,
|
||||
{},
|
||||
tr::lng_stats_overview_message_views);
|
||||
}
|
||||
if (s.publicForwards >= 0) {
|
||||
addSub(
|
||||
topRightLabel,
|
||||
{},
|
||||
tr::lng_stats_overview_message_public_shares);
|
||||
}
|
||||
if (s.reactions >= 0) {
|
||||
addSub(
|
||||
bottomLeftLabel,
|
||||
{},
|
||||
tr::lng_manage_peer_reactions);
|
||||
}
|
||||
if (s.privateForwards >= 0) {
|
||||
addSub(
|
||||
bottomRightLabel,
|
||||
{},
|
||||
tr::lng_stats_overview_message_private_shares);
|
||||
}
|
||||
}
|
||||
container->showChildren();
|
||||
container->sizeValue() | rpl::distinct_until_changed(
|
||||
) | rpl::on_next([=](const QSize &s) {
|
||||
const auto halfWidth = s.width() / 2;
|
||||
{
|
||||
const auto &p = st::statisticsOverviewValuePadding;
|
||||
topLeftLabel->moveToLeft(p.left(), p.top());
|
||||
}
|
||||
topRightLabel->moveToLeft(
|
||||
topLeftLabel->x() + halfWidth + st::statisticsOverviewRightSkip,
|
||||
topLeftLabel->y());
|
||||
bottomLeftLabel->moveToLeft(
|
||||
topLeftLabel->x(),
|
||||
topLeftLabel->y() + st::statisticsOverviewMidSkip);
|
||||
bottomRightLabel->moveToLeft(
|
||||
topRightLabel->x(),
|
||||
bottomLeftLabel->y());
|
||||
}, container->lifetime());
|
||||
Ui::AddSkip(content, st::statisticsLayerOverviewMargins.bottom());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void FillLoading(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
LoadingType type,
|
||||
rpl::producer<bool> toggleOn,
|
||||
rpl::producer<> showFinished) {
|
||||
const auto emptyWrap = container->add(
|
||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||
container,
|
||||
object_ptr<Ui::VerticalLayout>(container)));
|
||||
emptyWrap->toggleOn(std::move(toggleOn), anim::type::instant);
|
||||
|
||||
const auto content = emptyWrap->entity();
|
||||
const auto iconName = (type == LoadingType::Boosts)
|
||||
? u"stats_boosts"_q
|
||||
: (type == LoadingType::Earn)
|
||||
? u"stats_earn"_q
|
||||
: u"stats"_q;
|
||||
auto icon = ::Settings::CreateLottieIcon(
|
||||
content,
|
||||
{ .name = iconName, .sizeOverride = st::normalBoxLottieSize },
|
||||
st::settingsBlockedListIconPadding);
|
||||
|
||||
(
|
||||
std::move(showFinished) | rpl::take(1)
|
||||
) | rpl::on_next([animate = std::move(icon.animate)] {
|
||||
animate(anim::repeat::loop);
|
||||
}, icon.widget->lifetime());
|
||||
content->add(std::move(icon.widget));
|
||||
|
||||
content->add(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
content,
|
||||
(type == LoadingType::Boosts)
|
||||
? tr::lng_stats_boosts_loading()
|
||||
: (type == LoadingType::Earn)
|
||||
? tr::lng_stats_earn_loading()
|
||||
: tr::lng_stats_loading(),
|
||||
st::changePhoneTitle),
|
||||
st::changePhoneTitlePadding + st::boxRowPadding,
|
||||
style::al_top);
|
||||
|
||||
content->add(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
content,
|
||||
(type == LoadingType::Boosts)
|
||||
? tr::lng_stats_boosts_loading_subtext()
|
||||
: (type == LoadingType::Earn)
|
||||
? tr::lng_stats_earn_loading_subtext()
|
||||
: tr::lng_stats_loading_subtext(),
|
||||
st::statisticsLoadingSubtext),
|
||||
st::changePhoneDescriptionPadding + st::boxRowPadding,
|
||||
style::al_top
|
||||
)->setTryMakeSimilarLines(true);
|
||||
|
||||
Ui::AddSkip(content, st::settingsBlockedListIconPadding.top());
|
||||
}
|
||||
|
||||
InnerWidget::InnerWidget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
not_null<PeerData*> peer,
|
||||
FullMsgId contextId,
|
||||
FullStoryId storyId)
|
||||
: VerticalLayout(parent)
|
||||
, _controller(controller)
|
||||
, _peer(peer)
|
||||
, _contextId(contextId)
|
||||
, _storyId(storyId) {
|
||||
}
|
||||
|
||||
void InnerWidget::load() {
|
||||
const auto inner = this;
|
||||
|
||||
const auto descriptor = Descriptor{
|
||||
_peer,
|
||||
lifetime().make_state<Api::Statistics>(_peer->asChannel()),
|
||||
_controller->uiShow()->toastParent(),
|
||||
};
|
||||
|
||||
FillLoading(
|
||||
inner,
|
||||
Info::Statistics::LoadingType::Statistic,
|
||||
_loaded.events_starting_with(false) | rpl::map(!rpl::mappers::_1),
|
||||
_showFinished.events());
|
||||
|
||||
_showFinished.events(
|
||||
) | rpl::take(1) | rpl::on_next([=] {
|
||||
if (!_contextId && !_storyId) {
|
||||
descriptor.api->request(
|
||||
) | rpl::on_done([=] {
|
||||
_state.stats = Data::AnyStatistics{
|
||||
descriptor.api->channelStats(),
|
||||
descriptor.api->supergroupStats(),
|
||||
};
|
||||
fill();
|
||||
|
||||
}, lifetime());
|
||||
} else {
|
||||
const auto lifetimeApi = lifetime().make_state<rpl::lifetime>();
|
||||
const auto api = _storyId
|
||||
? lifetimeApi->make_state<Api::MessageStatistics>(
|
||||
descriptor.peer->asChannel(),
|
||||
_storyId)
|
||||
: lifetimeApi->make_state<Api::MessageStatistics>(
|
||||
descriptor.peer->asChannel(),
|
||||
_contextId);
|
||||
|
||||
api->request([=](const Data::StoryStatistics &data) {
|
||||
_state.stats = Data::AnyStatistics{
|
||||
.message = _contextId ? data : Data::StoryStatistics(),
|
||||
.story = _storyId ? data : Data::StoryStatistics(),
|
||||
};
|
||||
if (_contextId || _storyId) {
|
||||
_state.publicForwardsFirstSlice = api->firstSlice();
|
||||
}
|
||||
fill();
|
||||
|
||||
lifetimeApi->destroy();
|
||||
});
|
||||
}
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void InnerWidget::fill() {
|
||||
const auto wrap = this->add(
|
||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||
this,
|
||||
object_ptr<Ui::VerticalLayout>(this)));
|
||||
wrap->toggle(false, anim::type::instant);
|
||||
const auto inner = wrap->entity();
|
||||
const auto descriptor = Descriptor{
|
||||
_peer,
|
||||
lifetime().make_state<Api::Statistics>(_peer->asChannel()),
|
||||
_controller->uiShow()->toastParent(),
|
||||
};
|
||||
const auto finishLoading = [=] {
|
||||
_loaded.fire(true);
|
||||
wrap->toggle(true, anim::type::instant);
|
||||
this->resizeToWidth(width());
|
||||
this->showChildren();
|
||||
};
|
||||
if (_state.stats.message) {
|
||||
if (const auto i = _peer->owner().message(_contextId)) {
|
||||
Ui::AddSkip(inner);
|
||||
const auto preview = inner->add(
|
||||
object_ptr<MessagePreview>(inner, i, QImage()));
|
||||
AddContextMenu(preview, _controller, i);
|
||||
Ui::AddSkip(inner);
|
||||
Ui::AddDivider(inner);
|
||||
}
|
||||
} else if (_state.stats.story) {
|
||||
if (const auto story = _peer->owner().stories().lookup(_storyId)) {
|
||||
Ui::AddSkip(inner);
|
||||
const auto preview = inner->add(
|
||||
object_ptr<MessagePreview>(inner, *story, QImage()));
|
||||
preview->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
Ui::AddSkip(inner);
|
||||
Ui::AddDivider(inner);
|
||||
}
|
||||
}
|
||||
FillOverview(inner, _state.stats, false);
|
||||
if (_state.stats.channel) {
|
||||
FillOverview(inner, _state.stats, true);
|
||||
}
|
||||
FillStatistic(inner, descriptor, _state.stats, finishLoading);
|
||||
const auto &channel = _state.stats.channel;
|
||||
const auto &supergroup = _state.stats.supergroup;
|
||||
if (channel) {
|
||||
fillRecentPosts(inner);
|
||||
} else if (supergroup) {
|
||||
const auto showPeerInfo = [=](not_null<PeerData*> peer) {
|
||||
_showRequests.fire({ .info = peer->id });
|
||||
};
|
||||
const auto addSkip = [&](not_null<Ui::VerticalLayout*> c) {
|
||||
Ui::AddSkip(c);
|
||||
Ui::AddDivider(c);
|
||||
Ui::AddSkip(c);
|
||||
Ui::AddSkip(c);
|
||||
};
|
||||
if (!supergroup.topSenders.empty()) {
|
||||
AddMembersList(
|
||||
{ .topSenders = supergroup.topSenders },
|
||||
inner,
|
||||
showPeerInfo,
|
||||
descriptor.peer,
|
||||
tr::lng_stats_members_title());
|
||||
}
|
||||
if (!supergroup.topAdministrators.empty()) {
|
||||
addSkip(inner);
|
||||
AddMembersList(
|
||||
{ .topAdministrators
|
||||
= supergroup.topAdministrators },
|
||||
inner,
|
||||
showPeerInfo,
|
||||
descriptor.peer,
|
||||
tr::lng_stats_admins_title());
|
||||
}
|
||||
if (!supergroup.topInviters.empty()) {
|
||||
addSkip(inner);
|
||||
AddMembersList(
|
||||
{ .topInviters = supergroup.topInviters },
|
||||
inner,
|
||||
showPeerInfo,
|
||||
descriptor.peer,
|
||||
tr::lng_stats_inviters_title());
|
||||
}
|
||||
} else if (_state.stats.message || _state.stats.story) {
|
||||
using namespace Data;
|
||||
AddPublicForwards(
|
||||
_state.publicForwardsFirstSlice,
|
||||
inner,
|
||||
[=](RecentPostId id) {
|
||||
_showRequests.fire({
|
||||
.info = (!id.messageId && !id.storyId)
|
||||
? id.messageId.peer
|
||||
: PeerId(0),
|
||||
.history = id.messageId,
|
||||
.story = id.storyId,
|
||||
});
|
||||
},
|
||||
descriptor.peer,
|
||||
RecentPostId{ .messageId = _contextId, .storyId = _storyId });
|
||||
}
|
||||
}
|
||||
|
||||
void InnerWidget::fillRecentPosts(not_null<Ui::VerticalLayout*> container) {
|
||||
const auto &stats = _state.stats.channel;
|
||||
if (!stats || stats.recentMessageInteractions.empty()) {
|
||||
return;
|
||||
}
|
||||
_messagePreviews.reserve(stats.recentMessageInteractions.size());
|
||||
|
||||
const auto wrap = container->add(
|
||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||
container,
|
||||
object_ptr<Ui::VerticalLayout>(container)));
|
||||
const auto content = wrap->entity();
|
||||
AddHeader(content, tr::lng_stats_recent_messages_title, { stats, {} });
|
||||
Ui::AddSkip(content);
|
||||
|
||||
const auto addMessage = [=](
|
||||
not_null<Ui::VerticalLayout*> messageWrap,
|
||||
HistoryItem *maybeItem,
|
||||
Data::Story *maybeStory,
|
||||
const Data::StatisticsMessageInteractionInfo &info) {
|
||||
const auto button = messageWrap->add(
|
||||
object_ptr<Ui::SettingsButton>(
|
||||
messageWrap,
|
||||
rpl::never<QString>(),
|
||||
st::statisticsRecentPostButton));
|
||||
const auto fullRecentId = Data::RecentPostId{
|
||||
.messageId = maybeItem ? maybeItem->fullId() : FullMsgId(),
|
||||
.storyId = maybeStory ? maybeStory->fullId() : FullStoryId(),
|
||||
};
|
||||
auto it = _state.recentPostPreviews.find(fullRecentId);
|
||||
auto cachedPreview = (it != end(_state.recentPostPreviews))
|
||||
? base::take(it->second)
|
||||
: QImage();
|
||||
const auto raw = maybeItem
|
||||
? Ui::CreateChild<MessagePreview>(
|
||||
button,
|
||||
maybeItem,
|
||||
std::move(cachedPreview))
|
||||
: Ui::CreateChild<MessagePreview>(
|
||||
button,
|
||||
maybeStory,
|
||||
std::move(cachedPreview));
|
||||
raw->setInfo(
|
||||
info.viewsCount,
|
||||
info.forwardsCount,
|
||||
info.reactionsCount);
|
||||
|
||||
if (maybeItem) {
|
||||
AddContextMenu(button, _controller, maybeItem);
|
||||
}
|
||||
|
||||
_messagePreviews.push_back(raw);
|
||||
raw->show();
|
||||
button->sizeValue(
|
||||
) | rpl::on_next([=](const QSize &s) {
|
||||
if (!s.isNull()) {
|
||||
raw->setGeometry(Rect(s)
|
||||
- st::statisticsRecentPostButton.padding);
|
||||
}
|
||||
}, raw->lifetime());
|
||||
button->setClickedCallback([=] {
|
||||
_showRequests.fire({
|
||||
.messageStatistic = fullRecentId.messageId,
|
||||
.storyStatistic = fullRecentId.storyId,
|
||||
});
|
||||
});
|
||||
Ui::AddSkip(messageWrap);
|
||||
if (!wrap->toggled()) {
|
||||
wrap->toggle(true, anim::type::normal);
|
||||
}
|
||||
};
|
||||
|
||||
const auto buttonWrap = container->add(
|
||||
object_ptr<Ui::SlideWrap<Ui::SettingsButton>>(
|
||||
container,
|
||||
object_ptr<Ui::SettingsButton>(
|
||||
container,
|
||||
tr::lng_stories_show_more())));
|
||||
|
||||
constexpr auto kFirstPage = int(10);
|
||||
constexpr auto kPerPage = int(30);
|
||||
const auto max = int(stats.recentMessageInteractions.size());
|
||||
if (_state.recentPostsExpanded) {
|
||||
_state.recentPostsExpanded = std::max(
|
||||
_state.recentPostsExpanded - kPerPage,
|
||||
0);
|
||||
}
|
||||
const auto showMore = [=] {
|
||||
const auto from = _state.recentPostsExpanded;
|
||||
_state.recentPostsExpanded = std::min(
|
||||
max,
|
||||
_state.recentPostsExpanded
|
||||
? (_state.recentPostsExpanded + kPerPage)
|
||||
: kFirstPage);
|
||||
if (_state.recentPostsExpanded == max) {
|
||||
buttonWrap->toggle(false, anim::type::instant);
|
||||
}
|
||||
for (auto i = from; i < _state.recentPostsExpanded; i++) {
|
||||
const auto &recent = stats.recentMessageInteractions[i];
|
||||
const auto messageWrap = content->add(
|
||||
object_ptr<Ui::VerticalLayout>(content));
|
||||
auto &data = _peer->owner();
|
||||
if (recent.messageId) {
|
||||
const auto fullId = FullMsgId(_peer->id, recent.messageId);
|
||||
if (const auto item = data.message(fullId)) {
|
||||
addMessage(messageWrap, item, nullptr, recent);
|
||||
continue;
|
||||
}
|
||||
const auto callback = crl::guard(content, [=] {
|
||||
if (const auto item = _peer->owner().message(fullId)) {
|
||||
addMessage(messageWrap, item, nullptr, recent);
|
||||
content->resizeToWidth(content->width());
|
||||
}
|
||||
});
|
||||
_peer->session().api().requestMessageData(
|
||||
_peer,
|
||||
fullId.msg,
|
||||
callback);
|
||||
} else if (recent.storyId) {
|
||||
const auto fullId = FullStoryId{ _peer->id, recent.storyId };
|
||||
if (const auto story = data.stories().lookup(fullId)) {
|
||||
addMessage(messageWrap, nullptr, *story, recent);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
container->resizeToWidth(container->width());
|
||||
};
|
||||
const auto delay = st::defaultRippleAnimation.hideDuration;
|
||||
buttonWrap->entity()->setClickedCallback([=] {
|
||||
base::call_delayed(delay, crl::guard(container, showMore));
|
||||
});
|
||||
showMore();
|
||||
if (_messagePreviews.empty()) {
|
||||
wrap->toggle(false, anim::type::instant);
|
||||
}
|
||||
}
|
||||
|
||||
void InnerWidget::saveState(not_null<Memento*> memento) {
|
||||
for (const auto &message : _messagePreviews) {
|
||||
message->saveState(_state);
|
||||
}
|
||||
memento->setState(base::take(_state));
|
||||
}
|
||||
|
||||
void InnerWidget::restoreState(not_null<Memento*> memento) {
|
||||
_state = memento->state();
|
||||
if (_state.stats.channel
|
||||
|| _state.stats.supergroup
|
||||
|| _state.stats.message
|
||||
|| _state.stats.story) {
|
||||
fill();
|
||||
} else {
|
||||
load();
|
||||
}
|
||||
Ui::RpWidget::resizeToWidth(width());
|
||||
}
|
||||
|
||||
rpl::producer<Ui::ScrollToRequest> InnerWidget::scrollToRequests() const {
|
||||
return _scrollToRequests.events();
|
||||
}
|
||||
|
||||
auto InnerWidget::showRequests() const -> rpl::producer<ShowRequest> {
|
||||
return _showRequests.events();
|
||||
}
|
||||
|
||||
void InnerWidget::showFinished() {
|
||||
_showFinished.fire({});
|
||||
}
|
||||
|
||||
} // namespace Info::Statistics
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "base/object_ptr.h"
|
||||
#include "info/statistics/info_statistics_common.h"
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
|
||||
namespace Info {
|
||||
class Controller;
|
||||
} // namespace Info
|
||||
|
||||
namespace Info::Statistics {
|
||||
|
||||
class Memento;
|
||||
class MessagePreview;
|
||||
|
||||
enum class LoadingType {
|
||||
Statistic,
|
||||
Boosts,
|
||||
Earn,
|
||||
};
|
||||
|
||||
void FillLoading(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
LoadingType type,
|
||||
rpl::producer<bool> toggleOn,
|
||||
rpl::producer<> showFinished);
|
||||
|
||||
class InnerWidget final : public Ui::VerticalLayout {
|
||||
public:
|
||||
struct ShowRequest final {
|
||||
PeerId info = PeerId(0);
|
||||
FullMsgId history;
|
||||
FullMsgId messageStatistic;
|
||||
FullStoryId storyStatistic;
|
||||
FullStoryId story;
|
||||
};
|
||||
|
||||
InnerWidget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
not_null<PeerData*> peer,
|
||||
FullMsgId contextId,
|
||||
FullStoryId storyId);
|
||||
|
||||
[[nodiscard]] rpl::producer<Ui::ScrollToRequest> scrollToRequests() const;
|
||||
[[nodiscard]] rpl::producer<ShowRequest> showRequests() const;
|
||||
|
||||
void showFinished();
|
||||
|
||||
void saveState(not_null<Memento*> memento);
|
||||
void restoreState(not_null<Memento*> memento);
|
||||
|
||||
private:
|
||||
void load();
|
||||
void fill();
|
||||
void fillRecentPosts(not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
not_null<Controller*> _controller;
|
||||
not_null<PeerData*> _peer;
|
||||
FullMsgId _contextId;
|
||||
FullStoryId _storyId;
|
||||
|
||||
std::vector<not_null<MessagePreview*>> _messagePreviews;
|
||||
|
||||
SavedState _state;
|
||||
|
||||
rpl::event_stream<Ui::ScrollToRequest> _scrollToRequests;
|
||||
rpl::event_stream<ShowRequest> _showRequests;
|
||||
rpl::event_stream<> _showFinished;
|
||||
rpl::event_stream<bool> _loaded;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Info::Statistics
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
class PeerData;
|
||||
|
||||
namespace Ui {
|
||||
class SettingsButton;
|
||||
template <typename Widget>
|
||||
class SlideWrap;
|
||||
class VerticalLayout;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Data {
|
||||
struct Boost;
|
||||
struct BoostsListSlice;
|
||||
struct CreditsHistoryEntry;
|
||||
struct CreditsStatusSlice;
|
||||
struct PublicForwardsSlice;
|
||||
struct RecentPostId;
|
||||
struct SubscriptionEntry;
|
||||
struct SupergroupStatistics;
|
||||
} // namespace Data
|
||||
|
||||
namespace Main {
|
||||
class SessionShow;
|
||||
} // namespace Main
|
||||
|
||||
namespace Info::Statistics {
|
||||
|
||||
void AddPublicForwards(
|
||||
const Data::PublicForwardsSlice &firstSlice,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
Fn<void(Data::RecentPostId)> requestShow,
|
||||
not_null<PeerData*> peer,
|
||||
Data::RecentPostId contextId);
|
||||
|
||||
void AddMembersList(
|
||||
Data::SupergroupStatistics data,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
Fn<void(not_null<PeerData*>)> showPeerInfo,
|
||||
not_null<PeerData*> peer,
|
||||
rpl::producer<QString> title);
|
||||
|
||||
void AddBoostsList(
|
||||
const Data::BoostsListSlice &firstSlice,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
Fn<void(const Data::Boost &)> boostClickedCallback,
|
||||
not_null<PeerData*> peer,
|
||||
rpl::producer<QString> title);
|
||||
|
||||
using Clicked = Fn<void(
|
||||
const Data::CreditsHistoryEntry &,
|
||||
const Data::SubscriptionEntry &)>;
|
||||
void AddCreditsHistoryList(
|
||||
std::shared_ptr<Main::SessionShow> show,
|
||||
const Data::CreditsStatusSlice &firstSlice,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
Clicked entryClickedCallback,
|
||||
not_null<PeerData*> peer,
|
||||
bool in,
|
||||
bool out,
|
||||
bool subscription = false);
|
||||
|
||||
[[nodiscard]] not_null<Ui::SlideWrap<Ui::SettingsButton>*> AddShowMoreButton(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
rpl::producer<QString> title);
|
||||
|
||||
} // namespace Info::Statistics
|
||||
@@ -0,0 +1,358 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "info/statistics/info_statistics_recent_message.h"
|
||||
|
||||
#include "base/unixtime.h"
|
||||
#include "core/ui_integration.h"
|
||||
#include "data/data_document.h"
|
||||
#include "data/data_document_media.h"
|
||||
#include "data/data_file_origin.h"
|
||||
#include "data/data_photo.h"
|
||||
#include "data/data_photo_media.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_story.h"
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
#include "history/history_item_helpers.h"
|
||||
#include "history/view/history_view_item_preview.h"
|
||||
#include "info/statistics/info_statistics_common.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_session.h"
|
||||
#include "ui/controls/userpic_button.h"
|
||||
#include "ui/effects/outline_segments.h" // UnreadStoryOutlineGradient
|
||||
#include "ui/effects/ripple_animation.h"
|
||||
#include "ui/effects/spoiler_mess.h"
|
||||
#include "ui/painter.h"
|
||||
#include "ui/power_saving.h"
|
||||
#include "ui/rect.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/text/text_options.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_dialogs.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_statistics.h"
|
||||
|
||||
namespace Info::Statistics {
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] QImage PreparePreviewImage(
|
||||
QImage original,
|
||||
ImageRoundRadius radius,
|
||||
int size,
|
||||
bool spoiler) {
|
||||
if (original.width() * 10 < original.height()
|
||||
|| original.height() * 10 < original.width()) {
|
||||
return QImage();
|
||||
}
|
||||
const auto factor = style::DevicePixelRatio();
|
||||
size *= factor;
|
||||
const auto scaled = original.scaled(
|
||||
QSize(size, size),
|
||||
Qt::KeepAspectRatioByExpanding,
|
||||
Qt::FastTransformation);
|
||||
auto square = scaled.copy(
|
||||
(scaled.width() - size) / 2,
|
||||
(scaled.height() - size) / 2,
|
||||
size,
|
||||
size
|
||||
).convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
||||
if (spoiler) {
|
||||
square = Images::BlurLargeImage(
|
||||
std::move(square),
|
||||
style::ConvertScale(3) * factor);
|
||||
}
|
||||
square = Images::Round(std::move(square), radius);
|
||||
square.setDevicePixelRatio(factor);
|
||||
return square;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
MessagePreview::MessagePreview(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<HistoryItem*> item,
|
||||
QImage cachedPreview)
|
||||
: Ui::RpWidget(parent)
|
||||
, _messageId(item->fullId())
|
||||
, _date(
|
||||
st::statisticsHeaderTitleTextStyle,
|
||||
Ui::FormatDateTime(ItemDateTime(item)))
|
||||
, _preview(std::move(cachedPreview)) {
|
||||
_text.setMarkedText(
|
||||
st::defaultPeerListItem.nameStyle,
|
||||
item->toPreview({ .generateImages = false }).text,
|
||||
Ui::DialogTextOptions(),
|
||||
Core::TextContext({
|
||||
.session = &item->history()->session(),
|
||||
.repaint = [=] { update(); },
|
||||
}));
|
||||
if (item->media() && item->media()->hasSpoiler()) {
|
||||
_spoiler = std::make_unique<Ui::SpoilerAnimation>([=] { update(); });
|
||||
}
|
||||
if (_preview.isNull()) {
|
||||
if (const auto media = item->media()) {
|
||||
if (const auto photo = media->photo()) {
|
||||
_photoMedia = photo->createMediaView();
|
||||
_photoMedia->wanted(Data::PhotoSize::Large, item->fullId());
|
||||
} else if (const auto document = media->document()) {
|
||||
_documentMedia = document->createMediaView();
|
||||
_documentMedia->thumbnailWanted(item->fullId());
|
||||
}
|
||||
processPreview();
|
||||
}
|
||||
if ((!_documentMedia || _documentMedia->thumbnailSize().isNull())
|
||||
&& !_photoMedia) {
|
||||
const auto userpic = Ui::CreateChild<Ui::UserpicButton>(
|
||||
this,
|
||||
item->history()->peer,
|
||||
st::statisticsRecentPostUserpic);
|
||||
userpic->move(st::peerListBoxItem.photoPosition);
|
||||
userpic->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MessagePreview::MessagePreview(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<Data::Story*> story,
|
||||
QImage cachedPreview)
|
||||
: Ui::RpWidget(parent)
|
||||
, _storyId(story->fullId())
|
||||
, _date(
|
||||
st::statisticsHeaderTitleTextStyle,
|
||||
Ui::FormatDateTime(base::unixtime::parse(story->date())))
|
||||
, _preview(std::move(cachedPreview)) {
|
||||
_text.setMarkedText(
|
||||
st::defaultPeerListItem.nameStyle,
|
||||
{ tr::lng_in_dlg_story(tr::now) },
|
||||
Ui::DialogTextOptions(),
|
||||
Core::TextContext({
|
||||
.session = &story->peer()->session(),
|
||||
.repaint = [=] { update(); },
|
||||
}));
|
||||
if (_preview.isNull()) {
|
||||
if (const auto photo = story->photo()) {
|
||||
_photoMedia = photo->createMediaView();
|
||||
_photoMedia->wanted(Data::PhotoSize::Large, story->fullId());
|
||||
} else if (const auto document = story->document()) {
|
||||
_documentMedia = document->createMediaView();
|
||||
_documentMedia->thumbnailWanted(story->fullId());
|
||||
}
|
||||
processPreview();
|
||||
}
|
||||
}
|
||||
|
||||
void MessagePreview::setInfo(int views, int shares, int reactions) {
|
||||
_views = Ui::Text::String(
|
||||
st::defaultPeerListItem.nameStyle,
|
||||
(views >= 0)
|
||||
? tr::lng_stats_recent_messages_views(
|
||||
tr::now,
|
||||
lt_count_decimal,
|
||||
views)
|
||||
: QString());
|
||||
_shares = Ui::Text::String(
|
||||
st::statisticsHeaderTitleTextStyle,
|
||||
(shares > 0) ? Lang::FormatCountDecimal(shares) : QString());
|
||||
_reactions = Ui::Text::String(
|
||||
st::statisticsHeaderTitleTextStyle,
|
||||
(reactions > 0) ? Lang::FormatCountDecimal(reactions) : QString());
|
||||
_viewsWidth = (_views.maxWidth());
|
||||
_sharesWidth = (_shares.maxWidth());
|
||||
_reactionsWidth = (_reactions.maxWidth());
|
||||
}
|
||||
|
||||
void MessagePreview::processPreview() {
|
||||
const auto session = _photoMedia
|
||||
? &_photoMedia->owner()->session()
|
||||
: _documentMedia
|
||||
? &_documentMedia->owner()->session()
|
||||
: nullptr;
|
||||
if (!session) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct ThumbInfo final {
|
||||
bool loaded = false;
|
||||
Image *image = nullptr;
|
||||
};
|
||||
|
||||
const auto computeThumbInfo = [=]() -> ThumbInfo {
|
||||
using Size = Data::PhotoSize;
|
||||
if (_documentMedia) {
|
||||
return { true, _documentMedia->thumbnail() };
|
||||
} else if (const auto large = _photoMedia->image(Size::Large)) {
|
||||
return { true, large };
|
||||
} else if (const auto thumb = _photoMedia->image(Size::Thumbnail)) {
|
||||
return { false, thumb };
|
||||
} else if (const auto small = _photoMedia->image(Size::Small)) {
|
||||
return { false, small };
|
||||
} else {
|
||||
return { false, _photoMedia->thumbnailInline() };
|
||||
}
|
||||
};
|
||||
|
||||
rpl::single(rpl::empty) | rpl::then(
|
||||
session->downloaderTaskFinished()
|
||||
) | rpl::on_next([=] {
|
||||
const auto computed = computeThumbInfo();
|
||||
const auto guard = gsl::finally([&] { update(); });
|
||||
if (!computed.image) {
|
||||
if (_documentMedia && !_documentMedia->owner()->hasThumbnail()) {
|
||||
_preview = QImage();
|
||||
_lifetimeDownload.destroy();
|
||||
}
|
||||
return;
|
||||
} else if (computed.loaded) {
|
||||
_lifetimeDownload.destroy();
|
||||
}
|
||||
if (_storyId) {
|
||||
const auto line = st::dialogsStoriesFull.lineTwice;
|
||||
const auto rect = Rect(Size(st::peerListBoxItem.photoSize));
|
||||
const auto penWidth = line / 2.;
|
||||
const auto offset = 1.5 * penWidth * 2;
|
||||
const auto preview = PreparePreviewImage(
|
||||
computed.image->original(),
|
||||
ImageRoundRadius::Ellipse,
|
||||
st::peerListBoxItem.photoSize - offset * 2,
|
||||
!!_spoiler);
|
||||
auto image = QImage(
|
||||
rect.size() * style::DevicePixelRatio(),
|
||||
QImage::Format_ARGB32_Premultiplied);
|
||||
image.setDevicePixelRatio(style::DevicePixelRatio());
|
||||
image.fill(Qt::transparent);
|
||||
{
|
||||
auto p = QPainter(&image);
|
||||
p.drawImage(offset, offset, preview);
|
||||
auto hq = PainterHighQualityEnabler(p);
|
||||
auto gradient = Ui::UnreadStoryOutlineGradient();
|
||||
gradient.setStart(rect.topRight());
|
||||
gradient.setFinalStop(rect.bottomLeft());
|
||||
|
||||
p.setPen(QPen(gradient, penWidth));
|
||||
p.setBrush(Qt::NoBrush);
|
||||
p.drawEllipse(rect - Margins(penWidth));
|
||||
}
|
||||
_preview = std::move(image);
|
||||
} else {
|
||||
_preview = PreparePreviewImage(
|
||||
computed.image->original(),
|
||||
ImageRoundRadius::Large,
|
||||
st::peerListBoxItem.photoSize,
|
||||
!!_spoiler);
|
||||
}
|
||||
}, _lifetimeDownload);
|
||||
}
|
||||
|
||||
int MessagePreview::resizeGetHeight(int newWidth) {
|
||||
return st::peerListBoxItem.height;
|
||||
}
|
||||
|
||||
void MessagePreview::paintEvent(QPaintEvent *e) {
|
||||
auto p = QPainter(this);
|
||||
|
||||
const auto padding = st::boxRowPadding.left() / 2;
|
||||
const auto rightSubTextWidth = 0
|
||||
+ (_sharesWidth
|
||||
? _sharesWidth
|
||||
+ st::statisticsRecentPostShareIcon.width()
|
||||
+ st::statisticsRecentPostIconSkip
|
||||
: 0)
|
||||
+ (_reactionsWidth
|
||||
? _reactionsWidth
|
||||
+ st::statisticsRecentPostReactionIcon.width()
|
||||
+ st::statisticsChartRulerCaptionSkip
|
||||
+ st::statisticsRecentPostIconSkip
|
||||
: 0);
|
||||
const auto rightWidth = std::max(_viewsWidth, rightSubTextWidth)
|
||||
+ padding;
|
||||
const auto left = (false && _preview.isNull())
|
||||
? st::peerListBoxItem.photoPosition.x()
|
||||
: st::peerListBoxItem.namePosition.x();
|
||||
if (left) {
|
||||
const auto rect = QRect(
|
||||
st::peerListBoxItem.photoPosition,
|
||||
Size(st::peerListBoxItem.photoSize));
|
||||
p.drawImage(rect.topLeft(), _preview);
|
||||
if (_spoiler) {
|
||||
const auto paused = On(PowerSaving::kChatSpoiler);
|
||||
FillSpoilerRect(
|
||||
p,
|
||||
rect,
|
||||
Images::CornersMaskRef(
|
||||
Images::CornersMask(st::roundRadiusLarge)),
|
||||
Ui::DefaultImageSpoiler().frame(
|
||||
_spoiler->index(crl::now(), paused)),
|
||||
_cornerCache);
|
||||
}
|
||||
}
|
||||
const auto topTextTop = st::peerListBoxItem.namePosition.y();
|
||||
const auto bottomTextTop = st::peerListBoxItem.statusPosition.y();
|
||||
|
||||
p.setBrush(Qt::NoBrush);
|
||||
p.setPen(st::boxTextFg);
|
||||
_text.draw(p, {
|
||||
.position = { left, topTextTop },
|
||||
.outerWidth = width() - left,
|
||||
.availableWidth = width() - rightWidth - left,
|
||||
.spoiler = Ui::Text::DefaultSpoilerCache(),
|
||||
.now = crl::now(),
|
||||
.elisionHeight = st::statisticsDetailsPopupHeaderStyle.font->height,
|
||||
.elisionLines = 1,
|
||||
});
|
||||
_views.draw(p, {
|
||||
.position = { width() - _viewsWidth, topTextTop },
|
||||
.outerWidth = _viewsWidth,
|
||||
.availableWidth = _viewsWidth,
|
||||
});
|
||||
|
||||
p.setPen(st::windowSubTextFg);
|
||||
_date.draw(p, {
|
||||
.position = { left, bottomTextTop },
|
||||
.outerWidth = width() - left,
|
||||
.availableWidth = width() - rightWidth - left,
|
||||
});
|
||||
{
|
||||
auto right = width() - _sharesWidth;
|
||||
_shares.draw(p, {
|
||||
.position = { right, bottomTextTop },
|
||||
.outerWidth = _sharesWidth,
|
||||
.availableWidth = _sharesWidth,
|
||||
});
|
||||
const auto bottomTextBottom = bottomTextTop
|
||||
+ st::statisticsHeaderTitleTextStyle.font->height
|
||||
- st::statisticsRecentPostIconSkip;
|
||||
if (_sharesWidth) {
|
||||
const auto &icon = st::statisticsRecentPostShareIcon;
|
||||
const auto iconTop = bottomTextBottom - icon.height();
|
||||
right -= st::statisticsRecentPostIconSkip + icon.width();
|
||||
icon.paint(p, { right, iconTop }, width());
|
||||
}
|
||||
right -= _reactionsWidth + st::statisticsChartRulerCaptionSkip;
|
||||
_reactions.draw(p, {
|
||||
.position = { right, bottomTextTop },
|
||||
.outerWidth = _reactionsWidth,
|
||||
.availableWidth = _reactionsWidth,
|
||||
});
|
||||
if (_reactionsWidth) {
|
||||
const auto &icon = st::statisticsRecentPostReactionIcon;
|
||||
const auto iconTop = bottomTextBottom - icon.height();
|
||||
right -= st::statisticsRecentPostIconSkip + icon.width();
|
||||
icon.paint(p, { right, iconTop }, width());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessagePreview::saveState(SavedState &state) const {
|
||||
if (!_lifetimeDownload) {
|
||||
const auto fullId = Data::RecentPostId{ _messageId, _storyId };
|
||||
state.recentPostPreviews[fullId] = _preview;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Info::Statistics
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "ui/rp_widget.h"
|
||||
|
||||
class HistoryItem;
|
||||
|
||||
namespace Data {
|
||||
class DocumentMedia;
|
||||
class PhotoMedia;
|
||||
class Story;
|
||||
} // namespace Data
|
||||
|
||||
namespace Ui {
|
||||
class SpoilerAnimation;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Info::Statistics {
|
||||
|
||||
struct SavedState;
|
||||
|
||||
class MessagePreview final : public Ui::RpWidget {
|
||||
public:
|
||||
MessagePreview(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<HistoryItem*> item,
|
||||
QImage cachedPreview);
|
||||
MessagePreview(
|
||||
not_null<Ui::RpWidget*> parent,
|
||||
not_null<Data::Story*> story,
|
||||
QImage cachedPreview);
|
||||
|
||||
void setInfo(int views, int shares, int reactions);
|
||||
void saveState(SavedState &state) const;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
|
||||
int resizeGetHeight(int newWidth) override;
|
||||
|
||||
private:
|
||||
void processPreview();
|
||||
|
||||
FullMsgId _messageId;
|
||||
FullStoryId _storyId;
|
||||
Ui::Text::String _text;
|
||||
Ui::Text::String _date;
|
||||
Ui::Text::String _views;
|
||||
Ui::Text::String _shares;
|
||||
Ui::Text::String _reactions;
|
||||
|
||||
int _viewsWidth = 0;
|
||||
int _sharesWidth = 0;
|
||||
int _reactionsWidth = 0;
|
||||
|
||||
QImage _cornerCache;
|
||||
QImage _preview;
|
||||
|
||||
std::shared_ptr<Data::PhotoMedia> _photoMedia;
|
||||
std::shared_ptr<Data::DocumentMedia> _documentMedia;
|
||||
std::unique_ptr<Ui::SpoilerAnimation> _spoiler;
|
||||
|
||||
rpl::lifetime _lifetimeDownload;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Info::Statistics
|
||||
31
Telegram/SourceFiles/info/statistics/info_statistics_tag.h
Normal file
31
Telegram/SourceFiles/info/statistics/info_statistics_tag.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
class PeerData;
|
||||
|
||||
namespace Info::Statistics {
|
||||
|
||||
struct Tag final {
|
||||
explicit Tag() = default;
|
||||
explicit Tag(
|
||||
PeerData *peer,
|
||||
FullMsgId contextId,
|
||||
FullStoryId storyId)
|
||||
: peer(peer)
|
||||
, contextId(contextId)
|
||||
, storyId(storyId) {
|
||||
}
|
||||
|
||||
PeerData *peer = nullptr;
|
||||
FullMsgId contextId;
|
||||
FullStoryId storyId;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Info::Statistics
|
||||
152
Telegram/SourceFiles/info/statistics/info_statistics_widget.cpp
Normal file
152
Telegram/SourceFiles/info/statistics/info_statistics_widget.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "info/statistics/info_statistics_widget.h"
|
||||
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_stories.h"
|
||||
#include "info/info_controller.h"
|
||||
#include "info/info_memento.h"
|
||||
#include "info/statistics/info_statistics_inner_widget.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_session.h"
|
||||
#include "ui/ui_utility.h"
|
||||
|
||||
namespace Info::Statistics {
|
||||
|
||||
Memento::Memento(not_null<Controller*> controller)
|
||||
: ContentMemento(controller->statisticsTag()) {
|
||||
}
|
||||
|
||||
Memento::Memento(not_null<PeerData*> peer, FullMsgId contextId)
|
||||
: ContentMemento(Tag{ peer, contextId, {} }) {
|
||||
}
|
||||
|
||||
Memento::Memento(not_null<PeerData*> peer, FullStoryId storyId)
|
||||
: ContentMemento(Tag{ peer, {}, storyId }) {
|
||||
}
|
||||
|
||||
Memento::~Memento() = default;
|
||||
|
||||
Section Memento::section() const {
|
||||
return Section(Section::Type::Statistics);
|
||||
}
|
||||
|
||||
void Memento::setState(SavedState state) {
|
||||
_state = std::move(state);
|
||||
}
|
||||
|
||||
SavedState Memento::state() {
|
||||
return base::take(_state);
|
||||
}
|
||||
|
||||
object_ptr<ContentWidget> Memento::createWidget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
const QRect &geometry) {
|
||||
auto result = object_ptr<Widget>(parent, controller);
|
||||
result->setInternalState(geometry, this);
|
||||
return result;
|
||||
}
|
||||
|
||||
Widget::Widget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller)
|
||||
: ContentWidget(parent, controller)
|
||||
, _inner(setInnerWidget(
|
||||
object_ptr<InnerWidget>(
|
||||
this,
|
||||
controller,
|
||||
controller->statisticsTag().peer,
|
||||
controller->statisticsTag().contextId,
|
||||
controller->statisticsTag().storyId))) {
|
||||
_inner->showRequests(
|
||||
) | rpl::on_next([=](InnerWidget::ShowRequest request) {
|
||||
if (request.history) {
|
||||
controller->showPeerHistory(
|
||||
request.history.peer,
|
||||
Window::SectionShow::Way::Forward,
|
||||
request.history.msg);
|
||||
} else if (request.info) {
|
||||
controller->showPeerInfo(request.info);
|
||||
} else if (request.messageStatistic || request.storyStatistic) {
|
||||
controller->showSection(Make(
|
||||
controller->statisticsTag().peer,
|
||||
request.messageStatistic,
|
||||
request.storyStatistic));
|
||||
} else if (const auto &s = request.story) {
|
||||
if (const auto peer = controller->session().data().peer(s.peer)) {
|
||||
controller->parentController()->openPeerStory(
|
||||
peer,
|
||||
s.story,
|
||||
{ Data::StoriesContextSingle() });
|
||||
}
|
||||
}
|
||||
}, _inner->lifetime());
|
||||
_inner->scrollToRequests(
|
||||
) | rpl::on_next([this](const Ui::ScrollToRequest &request) {
|
||||
scrollTo(request);
|
||||
}, _inner->lifetime());
|
||||
}
|
||||
|
||||
bool Widget::showInternal(not_null<ContentMemento*> memento) {
|
||||
return false;
|
||||
}
|
||||
|
||||
rpl::producer<QString> Widget::title() {
|
||||
return controller()->statisticsTag().contextId
|
||||
? tr::lng_stats_message_title()
|
||||
: controller()->statisticsTag().storyId
|
||||
? tr::lng_stats_story_title()
|
||||
: tr::lng_stats_title();
|
||||
}
|
||||
|
||||
void Widget::setInternalState(
|
||||
const QRect &geometry,
|
||||
not_null<Memento*> memento) {
|
||||
setGeometry(geometry);
|
||||
Ui::SendPendingMoveResizeEvents(this);
|
||||
restoreState(memento);
|
||||
}
|
||||
|
||||
rpl::producer<bool> Widget::desiredShadowVisibility() const {
|
||||
return rpl::single<bool>(true);
|
||||
}
|
||||
|
||||
void Widget::showFinished() {
|
||||
_inner->showFinished();
|
||||
}
|
||||
|
||||
std::shared_ptr<ContentMemento> Widget::doCreateMemento() {
|
||||
auto result = std::make_shared<Memento>(controller());
|
||||
saveState(result.get());
|
||||
return result;
|
||||
}
|
||||
|
||||
void Widget::saveState(not_null<Memento*> memento) {
|
||||
memento->setScrollTop(scrollTopSave());
|
||||
_inner->saveState(memento);
|
||||
}
|
||||
|
||||
void Widget::restoreState(not_null<Memento*> memento) {
|
||||
_inner->restoreState(memento);
|
||||
scrollTopRestore(memento->scrollTop());
|
||||
}
|
||||
|
||||
std::shared_ptr<Info::Memento> Make(
|
||||
not_null<PeerData*> peer,
|
||||
FullMsgId contextId,
|
||||
FullStoryId storyId) {
|
||||
const auto memento = storyId
|
||||
? std::make_shared<Memento>(peer, storyId)
|
||||
: std::make_shared<Memento>(peer, contextId);
|
||||
return std::make_shared<Info::Memento>(
|
||||
std::vector<std::shared_ptr<ContentMemento>>(1, std::move(memento)));
|
||||
}
|
||||
|
||||
} // namespace Info::Statistics
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "info/info_content_widget.h"
|
||||
#include "info/statistics/info_statistics_common.h"
|
||||
|
||||
namespace Info::Statistics {
|
||||
|
||||
class InnerWidget;
|
||||
|
||||
class Memento final : public ContentMemento {
|
||||
public:
|
||||
Memento(not_null<Controller*> controller);
|
||||
Memento(not_null<PeerData*> peer, FullMsgId contextId);
|
||||
Memento(not_null<PeerData*> peer, FullStoryId storyId);
|
||||
~Memento();
|
||||
|
||||
object_ptr<ContentWidget> createWidget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
const QRect &geometry) override;
|
||||
|
||||
Section section() const override;
|
||||
|
||||
void setState(SavedState states);
|
||||
[[nodiscard]] SavedState state();
|
||||
|
||||
private:
|
||||
SavedState _state;
|
||||
|
||||
};
|
||||
|
||||
class Widget final : public ContentWidget {
|
||||
public:
|
||||
Widget(QWidget *parent, not_null<Controller*> controller);
|
||||
|
||||
bool showInternal(not_null<ContentMemento*> memento) override;
|
||||
rpl::producer<QString> title() override;
|
||||
rpl::producer<bool> desiredShadowVisibility() const override;
|
||||
void showFinished() override;
|
||||
|
||||
void setInternalState(
|
||||
const QRect &geometry,
|
||||
not_null<Memento*> memento);
|
||||
|
||||
private:
|
||||
void saveState(not_null<Memento*> memento);
|
||||
void restoreState(not_null<Memento*> memento);
|
||||
|
||||
std::shared_ptr<ContentMemento> doCreateMemento() override;
|
||||
|
||||
const not_null<InnerWidget*> _inner;
|
||||
|
||||
};
|
||||
|
||||
[[nodiscard]] std::shared_ptr<Info::Memento> Make(
|
||||
not_null<PeerData*> peer,
|
||||
FullMsgId contextId,
|
||||
FullStoryId storyId);
|
||||
|
||||
} // namespace Info::Statistics
|
||||
Reference in New Issue
Block a user