From 32b8d83c045a27812cd2912febb4f3d3d5f73810 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 27 Oct 2024 06:45:09 +0300 Subject: [PATCH] Moved out Info::Statistics::Tag to separated file. --- Telegram/CMakeLists.txt | 1 + .../info/bot/earn/info_bot_earn_widget.cpp | 10 ++---- .../boosts/info_boosts_widget.cpp | 10 ++---- .../earn/info_channel_earn_widget.cpp | 10 ++---- .../SourceFiles/info/info_content_widget.cpp | 12 ++----- .../SourceFiles/info/info_content_widget.h | 17 +++------- Telegram/SourceFiles/info/info_controller.cpp | 22 +++--------- Telegram/SourceFiles/info/info_controller.h | 34 +++---------------- .../SourceFiles/info/info_wrap_widget.cpp | 2 +- .../info/statistics/info_statistics_tag.h | 31 +++++++++++++++++ .../statistics/info_statistics_widget.cpp | 20 +++++------ 11 files changed, 65 insertions(+), 104 deletions(-) create mode 100644 Telegram/SourceFiles/info/statistics/info_statistics_tag.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 9656eda27d..c627861b39 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -995,6 +995,7 @@ PRIVATE info/statistics/info_statistics_list_controllers.h info/statistics/info_statistics_recent_message.cpp info/statistics/info_statistics_recent_message.h + info/statistics/info_statistics_tag.h info/statistics/info_statistics_widget.cpp info/statistics/info_statistics_widget.h info/stories/info_stories_inner_widget.cpp diff --git a/Telegram/SourceFiles/info/bot/earn/info_bot_earn_widget.cpp b/Telegram/SourceFiles/info/bot/earn/info_bot_earn_widget.cpp index 7eab7cf7b3..b38c436c6a 100644 --- a/Telegram/SourceFiles/info/bot/earn/info_bot_earn_widget.cpp +++ b/Telegram/SourceFiles/info/bot/earn/info_bot_earn_widget.cpp @@ -16,11 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Info::BotEarn { Memento::Memento(not_null controller) -: ContentMemento(Info::Statistics::Tag{ - controller->statisticsPeer(), - {}, - {}, -}) { +: ContentMemento(controller->statisticsTag()) { } Memento::Memento(not_null peer) @@ -58,7 +54,7 @@ Widget::Widget( object_ptr( this, controller, - controller->statisticsPeer()))) { + controller->statisticsTag().peer))) { _inner->showRequests( ) | rpl::start_with_next([=](InnerWidget::ShowRequest request) { }, _inner->lifetime()); @@ -73,7 +69,7 @@ not_null Widget::peer() const { } bool Widget::showInternal(not_null memento) { - return (memento->statisticsPeer() == peer()); + return (memento->statisticsTag().peer == peer()); } rpl::producer Widget::title() { diff --git a/Telegram/SourceFiles/info/channel_statistics/boosts/info_boosts_widget.cpp b/Telegram/SourceFiles/info/channel_statistics/boosts/info_boosts_widget.cpp index 60b37cb86b..447897dff3 100644 --- a/Telegram/SourceFiles/info/channel_statistics/boosts/info_boosts_widget.cpp +++ b/Telegram/SourceFiles/info/channel_statistics/boosts/info_boosts_widget.cpp @@ -16,11 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Info::Boosts { Memento::Memento(not_null controller) -: ContentMemento(Info::Statistics::Tag{ - controller->statisticsPeer(), - {}, - {}, -}) { +: ContentMemento(controller->statisticsTag()) { } Memento::Memento(not_null peer) @@ -58,7 +54,7 @@ Widget::Widget( object_ptr( this, controller, - controller->statisticsPeer()))) { + controller->statisticsTag().peer))) { _inner->showRequests( ) | rpl::start_with_next([=](InnerWidget::ShowRequest request) { }, _inner->lifetime()); @@ -73,7 +69,7 @@ not_null Widget::peer() const { } bool Widget::showInternal(not_null memento) { - return (memento->statisticsPeer() == peer()); + return (memento->statisticsTag().peer == peer()); } rpl::producer Widget::title() { diff --git a/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_widget.cpp b/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_widget.cpp index 3074468b66..99424a19dd 100644 --- a/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_widget.cpp +++ b/Telegram/SourceFiles/info/channel_statistics/earn/info_channel_earn_widget.cpp @@ -16,11 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Info::ChannelEarn { Memento::Memento(not_null controller) -: ContentMemento(Info::Statistics::Tag{ - controller->statisticsPeer(), - {}, - {}, -}) { +: ContentMemento(controller->statisticsTag()) { } Memento::Memento(not_null peer) @@ -58,7 +54,7 @@ Widget::Widget( object_ptr( this, controller, - controller->statisticsPeer()))) { + controller->statisticsTag().peer))) { _inner->showRequests( ) | rpl::start_with_next([=](InnerWidget::ShowRequest request) { }, _inner->lifetime()); @@ -73,7 +69,7 @@ not_null Widget::peer() const { } bool Widget::showInternal(not_null memento) { - return (memento->statisticsPeer() == peer()); + return (memento->statisticsTag().peer == peer()); } rpl::producer Widget::title() { diff --git a/Telegram/SourceFiles/info/info_content_widget.cpp b/Telegram/SourceFiles/info/info_content_widget.cpp index 507ce0f158..942864710c 100644 --- a/Telegram/SourceFiles/info/info_content_widget.cpp +++ b/Telegram/SourceFiles/info/info_content_widget.cpp @@ -375,12 +375,8 @@ Key ContentMemento::key() const { return Settings::Tag{ self }; } else if (const auto peer = storiesPeer()) { return Stories::Tag{ peer, storiesTab() }; - } else if (const auto peer = statisticsPeer()) { - return Statistics::Tag{ - peer, - statisticsContextId(), - statisticsStoryId(), - }; + } else if (const auto peer = statisticsTag().peer) { + return statisticsTag(); } else { return Downloads::Tag(); } @@ -418,9 +414,7 @@ ContentMemento::ContentMemento(Stories::Tag stories) } ContentMemento::ContentMemento(Statistics::Tag statistics) -: _statisticsPeer(statistics.peer) -, _statisticsContextId(statistics.contextId) -, _statisticsStoryId(statistics.storyId) { +: _statisticsTag(statistics) { } } // namespace Info diff --git a/Telegram/SourceFiles/info/info_content_widget.h b/Telegram/SourceFiles/info/info_content_widget.h index 7f7cd0f2f8..fd39d73842 100644 --- a/Telegram/SourceFiles/info/info_content_widget.h +++ b/Telegram/SourceFiles/info/info_content_widget.h @@ -7,9 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include -#include "ui/rp_widget.h" #include "info/info_wrap_widget.h" +#include "info/statistics/info_statistics_tag.h" namespace Dialogs::Stories { struct Content; @@ -216,14 +215,8 @@ public: Stories::Tab storiesTab() const { return _storiesTab; } - PeerData *statisticsPeer() const { - return _statisticsPeer; - } - FullMsgId statisticsContextId() const { - return _statisticsContextId; - } - FullStoryId statisticsStoryId() const { - return _statisticsStoryId; + Statistics::Tag statisticsTag() const { + return _statisticsTag; } PollData *poll() const { return _poll; @@ -269,9 +262,7 @@ private: UserData * const _settingsSelf = nullptr; PeerData * const _storiesPeer = nullptr; Stories::Tab _storiesTab = {}; - PeerData * const _statisticsPeer = nullptr; - const FullMsgId _statisticsContextId; - const FullStoryId _statisticsStoryId; + Statistics::Tag _statisticsTag; PollData * const _poll = nullptr; const FullMsgId _pollContextId; diff --git a/Telegram/SourceFiles/info/info_controller.cpp b/Telegram/SourceFiles/info/info_controller.cpp index 0cdd4bd610..7470b1d09e 100644 --- a/Telegram/SourceFiles/info/info_controller.cpp +++ b/Telegram/SourceFiles/info/info_controller.cpp @@ -92,25 +92,11 @@ Stories::Tab Key::storiesTab() const { return Stories::Tab(); } -PeerData *Key::statisticsPeer() const { +Statistics::Tag Key::statisticsTag() const { if (const auto tag = std::get_if(&_value)) { - return tag->peer; + return *tag; } - return nullptr; -} - -FullMsgId Key::statisticsContextId() const { - if (const auto tag = std::get_if(&_value)) { - return tag->contextId; - } - return {}; -} - -FullStoryId Key::statisticsStoryId() const { - if (const auto tag = std::get_if(&_value)) { - return tag->storyId; - } - return {}; + return Statistics::Tag(); } PollData *Key::poll() const { @@ -292,7 +278,7 @@ bool Controller::validateMementoPeer( && memento->migratedPeerId() == migratedPeerId() && memento->settingsSelf() == settingsSelf() && memento->storiesPeer() == storiesPeer() - && memento->statisticsPeer() == statisticsPeer(); + && memento->statisticsTag().peer == statisticsTag().peer; } void Controller::setSection(not_null memento) { diff --git a/Telegram/SourceFiles/info/info_controller.h b/Telegram/SourceFiles/info/info_controller.h index ee4a7fc335..f321e69563 100644 --- a/Telegram/SourceFiles/info/info_controller.h +++ b/Telegram/SourceFiles/info/info_controller.h @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "data/data_search_controller.h" +#include "info/statistics/info_statistics_tag.h" #include "window/window_session_controller.h" namespace Data { @@ -55,25 +56,6 @@ struct Tag { } // namespace Info::Stories -namespace Info::Statistics { - -struct Tag { - explicit Tag( - not_null peer, - FullMsgId contextId, - FullStoryId storyId) - : peer(peer) - , contextId(contextId) - , storyId(storyId) { - } - - not_null peer; - FullMsgId contextId; - FullStoryId storyId; -}; - -} // namespace Info::Statistics - namespace Info { class Key { @@ -92,9 +74,7 @@ public: bool isDownloads() const; PeerData *storiesPeer() const; Stories::Tab storiesTab() const; - PeerData *statisticsPeer() const; - FullMsgId statisticsContextId() const; - FullStoryId statisticsStoryId() const; + Statistics::Tag statisticsTag() const; PollData *poll() const; FullMsgId pollContextId() const; @@ -199,14 +179,8 @@ public: [[nodiscard]] Stories::Tab storiesTab() const { return key().storiesTab(); } - [[nodiscard]] PeerData *statisticsPeer() const { - return key().statisticsPeer(); - } - [[nodiscard]] FullMsgId statisticsContextId() const { - return key().statisticsContextId(); - } - [[nodiscard]] FullStoryId statisticsStoryId() const { - return key().statisticsStoryId(); + [[nodiscard]] Statistics::Tag statisticsTag() const { + return key().statisticsTag(); } [[nodiscard]] PollData *poll() const; [[nodiscard]] FullMsgId pollContextId() const { diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index 992f9f4950..363558e59c 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -290,7 +290,7 @@ Dialogs::RowDescriptor WrapWidget::activeChat() const { } else if (key().settingsSelf() || key().isDownloads() || key().poll() - || key().statisticsPeer()) { + || key().statisticsTag().peer) { return Dialogs::RowDescriptor(); } Unexpected("Owner in WrapWidget::activeChat()."); diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_tag.h b/Telegram/SourceFiles/info/statistics/info_statistics_tag.h new file mode 100644 index 0000000000..e2bc2760fc --- /dev/null +++ b/Telegram/SourceFiles/info/statistics/info_statistics_tag.h @@ -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 diff --git a/Telegram/SourceFiles/info/statistics/info_statistics_widget.cpp b/Telegram/SourceFiles/info/statistics/info_statistics_widget.cpp index fc40d9e09f..087d3dd11e 100644 --- a/Telegram/SourceFiles/info/statistics/info_statistics_widget.cpp +++ b/Telegram/SourceFiles/info/statistics/info_statistics_widget.cpp @@ -19,11 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Info::Statistics { Memento::Memento(not_null controller) -: ContentMemento(Tag{ - controller->statisticsPeer(), - controller->statisticsContextId(), - controller->statisticsStoryId(), -}) { +: ContentMemento(controller->statisticsTag()) { } Memento::Memento(not_null peer, FullMsgId contextId) @@ -65,9 +61,9 @@ Widget::Widget( object_ptr( this, controller, - controller->statisticsPeer(), - controller->statisticsContextId(), - controller->statisticsStoryId()))) { + controller->statisticsTag().peer, + controller->statisticsTag().contextId, + controller->statisticsTag().storyId))) { _inner->showRequests( ) | rpl::start_with_next([=](InnerWidget::ShowRequest request) { if (request.history) { @@ -79,7 +75,7 @@ Widget::Widget( controller->showPeerInfo(request.info); } else if (request.messageStatistic || request.storyStatistic) { controller->showSection(Make( - controller->statisticsPeer(), + controller->statisticsTag().peer, request.messageStatistic, request.storyStatistic)); } else if (const auto &s = request.story) { @@ -92,7 +88,7 @@ Widget::Widget( } }, _inner->lifetime()); _inner->scrollToRequests( - ) | rpl::start_with_next([=](const Ui::ScrollToRequest &request) { + ) | rpl::start_with_next([this](const Ui::ScrollToRequest &request) { scrollTo(request); }, _inner->lifetime()); } @@ -102,9 +98,9 @@ bool Widget::showInternal(not_null memento) { } rpl::producer Widget::title() { - return controller()->statisticsContextId() + return controller()->statisticsTag().contextId ? tr::lng_stats_message_title() - : controller()->statisticsStoryId() + : controller()->statisticsTag().storyId ? tr::lng_stats_story_title() : tr::lng_stats_title(); }