From 34d0dac351af78ea899bf35fb87f9729dbd07950 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 17 Nov 2023 04:59:20 +0300 Subject: [PATCH] Added ability to create statistics info layer with story id. --- .../history/history_inner_widget.cpp | 2 +- .../info/boosts/info_boosts_widget.cpp | 5 +-- .../SourceFiles/info/info_content_widget.cpp | 9 +++-- .../SourceFiles/info/info_content_widget.h | 4 +++ Telegram/SourceFiles/info/info_controller.cpp | 7 ++++ Telegram/SourceFiles/info/info_controller.h | 13 ++++++-- .../info_statistics_inner_widget.cpp | 14 +++----- .../statistics/info_statistics_inner_widget.h | 7 ++-- .../statistics/info_statistics_widget.cpp | 33 ++++++++++--------- .../info/statistics/info_statistics_widget.h | 7 ++-- .../SourceFiles/window/window_peer_menu.cpp | 3 +- 11 files changed, 62 insertions(+), 42 deletions(-) diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index dfed773ba..7605fa91a 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2283,7 +2283,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { if (channel->flags() & ChannelDataFlag::CanGetStatistics) { auto callback = crl::guard(controller, [=] { controller->showSection( - Info::Statistics::Make(channel, itemId)); + Info::Statistics::Make(channel, itemId, {})); }); _menu->addAction( tr::lng_stats_title(tr::now), diff --git a/Telegram/SourceFiles/info/boosts/info_boosts_widget.cpp b/Telegram/SourceFiles/info/boosts/info_boosts_widget.cpp index 5e4d8ed32..b1db67544 100644 --- a/Telegram/SourceFiles/info/boosts/info_boosts_widget.cpp +++ b/Telegram/SourceFiles/info/boosts/info_boosts_widget.cpp @@ -17,12 +17,13 @@ namespace Info::Boosts { Memento::Memento(not_null controller) : ContentMemento(Info::Statistics::Tag{ controller->statisticsPeer(), - {} + {}, + {}, }) { } Memento::Memento(not_null peer) -: ContentMemento(Info::Statistics::Tag{ peer, {} }) { +: ContentMemento(Info::Statistics::Tag{ peer, {}, {} }) { } Memento::~Memento() = default; diff --git a/Telegram/SourceFiles/info/info_content_widget.cpp b/Telegram/SourceFiles/info/info_content_widget.cpp index 89c0f7aad..8cf7a38d5 100644 --- a/Telegram/SourceFiles/info/info_content_widget.cpp +++ b/Telegram/SourceFiles/info/info_content_widget.cpp @@ -340,7 +340,11 @@ Key ContentMemento::key() const { } else if (const auto peer = storiesPeer()) { return Stories::Tag{ peer, storiesTab() }; } else if (const auto peer = statisticsPeer()) { - return Statistics::Tag{ peer, statisticsContextId() }; + return Statistics::Tag{ + peer, + statisticsContextId(), + statisticsStoryId(), + }; } else { return Downloads::Tag(); } @@ -379,7 +383,8 @@ ContentMemento::ContentMemento(Stories::Tag stories) ContentMemento::ContentMemento(Statistics::Tag statistics) : _statisticsPeer(statistics.peer) -, _statisticsContextId(statistics.contextId) { +, _statisticsContextId(statistics.contextId) +, _statisticsStoryId(statistics.storyId) { } } // namespace Info diff --git a/Telegram/SourceFiles/info/info_content_widget.h b/Telegram/SourceFiles/info/info_content_widget.h index 5f0c8480e..5d53efee5 100644 --- a/Telegram/SourceFiles/info/info_content_widget.h +++ b/Telegram/SourceFiles/info/info_content_widget.h @@ -202,6 +202,9 @@ public: FullMsgId statisticsContextId() const { return _statisticsContextId; } + FullStoryId statisticsStoryId() const { + return _statisticsStoryId; + } PollData *poll() const { return _poll; } @@ -248,6 +251,7 @@ private: Stories::Tab _storiesTab = {}; PeerData * const _statisticsPeer = nullptr; const FullMsgId _statisticsContextId; + const FullStoryId _statisticsStoryId; PollData * const _poll = nullptr; const FullMsgId _pollContextId; diff --git a/Telegram/SourceFiles/info/info_controller.cpp b/Telegram/SourceFiles/info/info_controller.cpp index 48426de06..0cdd4bd61 100644 --- a/Telegram/SourceFiles/info/info_controller.cpp +++ b/Telegram/SourceFiles/info/info_controller.cpp @@ -106,6 +106,13 @@ FullMsgId Key::statisticsContextId() const { return {}; } +FullStoryId Key::statisticsStoryId() const { + if (const auto tag = std::get_if(&_value)) { + return tag->storyId; + } + return {}; +} + PollData *Key::poll() const { if (const auto data = std::get_if(&_value)) { return data->poll; diff --git a/Telegram/SourceFiles/info/info_controller.h b/Telegram/SourceFiles/info/info_controller.h index cb779f37f..33ef698f1 100644 --- a/Telegram/SourceFiles/info/info_controller.h +++ b/Telegram/SourceFiles/info/info_controller.h @@ -58,13 +58,18 @@ struct Tag { namespace Info::Statistics { struct Tag { - explicit Tag(not_null peer, FullMsgId contextId) + explicit Tag( + not_null peer, + FullMsgId contextId, + FullStoryId storyId) : peer(peer) - , contextId(contextId) { + , contextId(contextId) + , storyId(storyId) { } not_null peer; FullMsgId contextId; + FullStoryId storyId; }; } // namespace Info::Statistics @@ -89,6 +94,7 @@ public: Stories::Tab storiesTab() const; PeerData *statisticsPeer() const; FullMsgId statisticsContextId() const; + FullStoryId statisticsStoryId() const; PollData *poll() const; FullMsgId pollContextId() const; @@ -194,6 +200,9 @@ public: [[nodiscard]] FullMsgId statisticsContextId() const { return key().statisticsContextId(); } + [[nodiscard]] FullStoryId statisticsStoryId() const { + return key().statisticsStoryId(); + } [[nodiscard]] PollData *poll() const; [[nodiscard]] FullMsgId pollContextId() const { return key().pollContextId(); diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp index 950b27ca3..da4732f79 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.cpp @@ -533,11 +533,13 @@ InnerWidget::InnerWidget( QWidget *parent, not_null controller, not_null peer, - FullMsgId contextId) + FullMsgId contextId, + FullStoryId storyId) : VerticalLayout(parent) , _controller(controller) , _peer(peer) -, _contextId(contextId) { +, _contextId(contextId) +, _storyId(storyId) { } void InnerWidget::load() { @@ -803,13 +805,5 @@ void InnerWidget::showFinished() { _showFinished.fire({}); } -not_null InnerWidget::peer() const { - return _peer; -} - -FullMsgId InnerWidget::contextId() const { - return _contextId; -} - } // namespace Info::Statistics diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.h b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.h index f2e21a6c1..d71091298 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.h +++ b/Telegram/SourceFiles/info/statistics/info_statistics_inner_widget.h @@ -38,10 +38,8 @@ public: QWidget *parent, not_null controller, not_null peer, - FullMsgId contextId); - - [[nodiscard]] not_null peer() const; - [[nodiscard]] FullMsgId contextId() const; + FullMsgId contextId, + FullStoryId storyId); [[nodiscard]] rpl::producer scrollToRequests() const; [[nodiscard]] rpl::producer showRequests() const; @@ -59,6 +57,7 @@ private: not_null _controller; not_null _peer; FullMsgId _contextId; + FullStoryId _storyId; std::vector> _messagePreviews; diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_widget.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_widget.cpp index 1edae544a..a21b8b30d 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_widget.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_widget.cpp @@ -18,11 +18,16 @@ Memento::Memento(not_null controller) : ContentMemento(Tag{ controller->statisticsPeer(), controller->statisticsContextId(), + controller->statisticsStoryId(), }) { } Memento::Memento(not_null peer, FullMsgId contextId) -: ContentMemento(Tag{ peer, contextId }) { +: ContentMemento(Tag{ peer, contextId, {} }) { +} + +Memento::Memento(not_null peer, FullStoryId storyId) +: ContentMemento(Tag{ peer, {}, storyId }) { } Memento::~Memento() = default; @@ -57,7 +62,8 @@ Widget::Widget( this, controller, controller->statisticsPeer(), - controller->statisticsContextId()))) { + controller->statisticsContextId(), + controller->statisticsStoryId()))) { _inner->showRequests( ) | rpl::start_with_next([=](InnerWidget::ShowRequest request) { if (request.history) { @@ -70,7 +76,8 @@ Widget::Widget( } else if (request.messageStatistic) { controller->showSection(Make( controller->statisticsPeer(), - request.messageStatistic)); + request.messageStatistic, + {})); } }, _inner->lifetime()); _inner->scrollToRequests( @@ -79,20 +86,12 @@ Widget::Widget( }, _inner->lifetime()); } -not_null Widget::peer() const { - return _inner->peer(); -} - -FullMsgId Widget::contextId() const { - return _inner->contextId(); -} - bool Widget::showInternal(not_null memento) { return false; } rpl::producer Widget::title() { - return _inner->contextId() + return controller()->statisticsContextId() ? tr::lng_stats_message_title() : tr::lng_stats_title(); } @@ -131,11 +130,13 @@ void Widget::restoreState(not_null memento) { std::shared_ptr Make( not_null peer, - FullMsgId contextId) { + FullMsgId contextId, + FullStoryId storyId) { + const auto memento = storyId + ? std::make_shared(peer, storyId) + : std::make_shared(peer, contextId); return std::make_shared( - std::vector>( - 1, - std::make_shared(peer, contextId))); + std::vector>(1, std::move(memento))); } } // namespace Info::Statistics diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_widget.h b/Telegram/SourceFiles/info/statistics/info_statistics_widget.h index 172db8f3e..627fde455 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_widget.h +++ b/Telegram/SourceFiles/info/statistics/info_statistics_widget.h @@ -18,6 +18,7 @@ class Memento final : public ContentMemento { public: Memento(not_null controller); Memento(not_null peer, FullMsgId contextId); + Memento(not_null peer, FullStoryId storyId); ~Memento(); object_ptr createWidget( @@ -44,9 +45,6 @@ public: rpl::producer desiredShadowVisibility() const override; void showFinished() override; - [[nodiscard]] not_null peer() const; - [[nodiscard]] FullMsgId contextId() const; - void setInternalState( const QRect &geometry, not_null memento); @@ -63,6 +61,7 @@ private: [[nodiscard]] std::shared_ptr Make( not_null peer, - FullMsgId contextId); + FullMsgId contextId, + FullStoryId storyId); } // namespace Info::Statistics diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 683b00a3d..77213a5c6 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -1008,7 +1008,8 @@ void Filler::addViewStatistics() { if (channel->flags() & ChannelDataFlag::CanGetStatistics) { _addAction(tr::lng_stats_title(tr::now), [=] { if (const auto strong = weak.get()) { - controller->showSection(Info::Statistics::Make(peer, {})); + using namespace Info; + controller->showSection(Statistics::Make(peer, {}, {})); } }, &st::menuIconStats); }