Moved out Info::Statistics::Tag to separated file.

This commit is contained in:
23rd 2024-10-27 06:45:09 +03:00
parent bf55c325ce
commit 32b8d83c04
11 changed files with 65 additions and 104 deletions

View file

@ -995,6 +995,7 @@ PRIVATE
info/statistics/info_statistics_list_controllers.h info/statistics/info_statistics_list_controllers.h
info/statistics/info_statistics_recent_message.cpp info/statistics/info_statistics_recent_message.cpp
info/statistics/info_statistics_recent_message.h info/statistics/info_statistics_recent_message.h
info/statistics/info_statistics_tag.h
info/statistics/info_statistics_widget.cpp info/statistics/info_statistics_widget.cpp
info/statistics/info_statistics_widget.h info/statistics/info_statistics_widget.h
info/stories/info_stories_inner_widget.cpp info/stories/info_stories_inner_widget.cpp

View file

@ -16,11 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Info::BotEarn { namespace Info::BotEarn {
Memento::Memento(not_null<Controller*> controller) Memento::Memento(not_null<Controller*> controller)
: ContentMemento(Info::Statistics::Tag{ : ContentMemento(controller->statisticsTag()) {
controller->statisticsPeer(),
{},
{},
}) {
} }
Memento::Memento(not_null<PeerData*> peer) Memento::Memento(not_null<PeerData*> peer)
@ -58,7 +54,7 @@ Widget::Widget(
object_ptr<InnerWidget>( object_ptr<InnerWidget>(
this, this,
controller, controller,
controller->statisticsPeer()))) { controller->statisticsTag().peer))) {
_inner->showRequests( _inner->showRequests(
) | rpl::start_with_next([=](InnerWidget::ShowRequest request) { ) | rpl::start_with_next([=](InnerWidget::ShowRequest request) {
}, _inner->lifetime()); }, _inner->lifetime());
@ -73,7 +69,7 @@ not_null<PeerData*> Widget::peer() const {
} }
bool Widget::showInternal(not_null<ContentMemento*> memento) { bool Widget::showInternal(not_null<ContentMemento*> memento) {
return (memento->statisticsPeer() == peer()); return (memento->statisticsTag().peer == peer());
} }
rpl::producer<QString> Widget::title() { rpl::producer<QString> Widget::title() {

View file

@ -16,11 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Info::Boosts { namespace Info::Boosts {
Memento::Memento(not_null<Controller*> controller) Memento::Memento(not_null<Controller*> controller)
: ContentMemento(Info::Statistics::Tag{ : ContentMemento(controller->statisticsTag()) {
controller->statisticsPeer(),
{},
{},
}) {
} }
Memento::Memento(not_null<PeerData*> peer) Memento::Memento(not_null<PeerData*> peer)
@ -58,7 +54,7 @@ Widget::Widget(
object_ptr<InnerWidget>( object_ptr<InnerWidget>(
this, this,
controller, controller,
controller->statisticsPeer()))) { controller->statisticsTag().peer))) {
_inner->showRequests( _inner->showRequests(
) | rpl::start_with_next([=](InnerWidget::ShowRequest request) { ) | rpl::start_with_next([=](InnerWidget::ShowRequest request) {
}, _inner->lifetime()); }, _inner->lifetime());
@ -73,7 +69,7 @@ not_null<PeerData*> Widget::peer() const {
} }
bool Widget::showInternal(not_null<ContentMemento*> memento) { bool Widget::showInternal(not_null<ContentMemento*> memento) {
return (memento->statisticsPeer() == peer()); return (memento->statisticsTag().peer == peer());
} }
rpl::producer<QString> Widget::title() { rpl::producer<QString> Widget::title() {

View file

@ -16,11 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Info::ChannelEarn { namespace Info::ChannelEarn {
Memento::Memento(not_null<Controller*> controller) Memento::Memento(not_null<Controller*> controller)
: ContentMemento(Info::Statistics::Tag{ : ContentMemento(controller->statisticsTag()) {
controller->statisticsPeer(),
{},
{},
}) {
} }
Memento::Memento(not_null<PeerData*> peer) Memento::Memento(not_null<PeerData*> peer)
@ -58,7 +54,7 @@ Widget::Widget(
object_ptr<InnerWidget>( object_ptr<InnerWidget>(
this, this,
controller, controller,
controller->statisticsPeer()))) { controller->statisticsTag().peer))) {
_inner->showRequests( _inner->showRequests(
) | rpl::start_with_next([=](InnerWidget::ShowRequest request) { ) | rpl::start_with_next([=](InnerWidget::ShowRequest request) {
}, _inner->lifetime()); }, _inner->lifetime());
@ -73,7 +69,7 @@ not_null<PeerData*> Widget::peer() const {
} }
bool Widget::showInternal(not_null<ContentMemento*> memento) { bool Widget::showInternal(not_null<ContentMemento*> memento) {
return (memento->statisticsPeer() == peer()); return (memento->statisticsTag().peer == peer());
} }
rpl::producer<QString> Widget::title() { rpl::producer<QString> Widget::title() {

View file

@ -375,12 +375,8 @@ Key ContentMemento::key() const {
return Settings::Tag{ self }; return Settings::Tag{ self };
} else if (const auto peer = storiesPeer()) { } else if (const auto peer = storiesPeer()) {
return Stories::Tag{ peer, storiesTab() }; return Stories::Tag{ peer, storiesTab() };
} else if (const auto peer = statisticsPeer()) { } else if (const auto peer = statisticsTag().peer) {
return Statistics::Tag{ return statisticsTag();
peer,
statisticsContextId(),
statisticsStoryId(),
};
} else { } else {
return Downloads::Tag(); return Downloads::Tag();
} }
@ -418,9 +414,7 @@ ContentMemento::ContentMemento(Stories::Tag stories)
} }
ContentMemento::ContentMemento(Statistics::Tag statistics) ContentMemento::ContentMemento(Statistics::Tag statistics)
: _statisticsPeer(statistics.peer) : _statisticsTag(statistics) {
, _statisticsContextId(statistics.contextId)
, _statisticsStoryId(statistics.storyId) {
} }
} // namespace Info } // namespace Info

View file

@ -7,9 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include <rpl/variable.h>
#include "ui/rp_widget.h"
#include "info/info_wrap_widget.h" #include "info/info_wrap_widget.h"
#include "info/statistics/info_statistics_tag.h"
namespace Dialogs::Stories { namespace Dialogs::Stories {
struct Content; struct Content;
@ -216,14 +215,8 @@ public:
Stories::Tab storiesTab() const { Stories::Tab storiesTab() const {
return _storiesTab; return _storiesTab;
} }
PeerData *statisticsPeer() const { Statistics::Tag statisticsTag() const {
return _statisticsPeer; return _statisticsTag;
}
FullMsgId statisticsContextId() const {
return _statisticsContextId;
}
FullStoryId statisticsStoryId() const {
return _statisticsStoryId;
} }
PollData *poll() const { PollData *poll() const {
return _poll; return _poll;
@ -269,9 +262,7 @@ private:
UserData * const _settingsSelf = nullptr; UserData * const _settingsSelf = nullptr;
PeerData * const _storiesPeer = nullptr; PeerData * const _storiesPeer = nullptr;
Stories::Tab _storiesTab = {}; Stories::Tab _storiesTab = {};
PeerData * const _statisticsPeer = nullptr; Statistics::Tag _statisticsTag;
const FullMsgId _statisticsContextId;
const FullStoryId _statisticsStoryId;
PollData * const _poll = nullptr; PollData * const _poll = nullptr;
const FullMsgId _pollContextId; const FullMsgId _pollContextId;

View file

@ -92,25 +92,11 @@ Stories::Tab Key::storiesTab() const {
return Stories::Tab(); return Stories::Tab();
} }
PeerData *Key::statisticsPeer() const { Statistics::Tag Key::statisticsTag() const {
if (const auto tag = std::get_if<Statistics::Tag>(&_value)) { if (const auto tag = std::get_if<Statistics::Tag>(&_value)) {
return tag->peer; return *tag;
} }
return nullptr; return Statistics::Tag();
}
FullMsgId Key::statisticsContextId() const {
if (const auto tag = std::get_if<Statistics::Tag>(&_value)) {
return tag->contextId;
}
return {};
}
FullStoryId Key::statisticsStoryId() const {
if (const auto tag = std::get_if<Statistics::Tag>(&_value)) {
return tag->storyId;
}
return {};
} }
PollData *Key::poll() const { PollData *Key::poll() const {
@ -292,7 +278,7 @@ bool Controller::validateMementoPeer(
&& memento->migratedPeerId() == migratedPeerId() && memento->migratedPeerId() == migratedPeerId()
&& memento->settingsSelf() == settingsSelf() && memento->settingsSelf() == settingsSelf()
&& memento->storiesPeer() == storiesPeer() && memento->storiesPeer() == storiesPeer()
&& memento->statisticsPeer() == statisticsPeer(); && memento->statisticsTag().peer == statisticsTag().peer;
} }
void Controller::setSection(not_null<ContentMemento*> memento) { void Controller::setSection(not_null<ContentMemento*> memento) {

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once #pragma once
#include "data/data_search_controller.h" #include "data/data_search_controller.h"
#include "info/statistics/info_statistics_tag.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
namespace Data { namespace Data {
@ -55,25 +56,6 @@ struct Tag {
} // namespace Info::Stories } // namespace Info::Stories
namespace Info::Statistics {
struct Tag {
explicit Tag(
not_null<PeerData*> peer,
FullMsgId contextId,
FullStoryId storyId)
: peer(peer)
, contextId(contextId)
, storyId(storyId) {
}
not_null<PeerData*> peer;
FullMsgId contextId;
FullStoryId storyId;
};
} // namespace Info::Statistics
namespace Info { namespace Info {
class Key { class Key {
@ -92,9 +74,7 @@ public:
bool isDownloads() const; bool isDownloads() const;
PeerData *storiesPeer() const; PeerData *storiesPeer() const;
Stories::Tab storiesTab() const; Stories::Tab storiesTab() const;
PeerData *statisticsPeer() const; Statistics::Tag statisticsTag() const;
FullMsgId statisticsContextId() const;
FullStoryId statisticsStoryId() const;
PollData *poll() const; PollData *poll() const;
FullMsgId pollContextId() const; FullMsgId pollContextId() const;
@ -199,14 +179,8 @@ public:
[[nodiscard]] Stories::Tab storiesTab() const { [[nodiscard]] Stories::Tab storiesTab() const {
return key().storiesTab(); return key().storiesTab();
} }
[[nodiscard]] PeerData *statisticsPeer() const { [[nodiscard]] Statistics::Tag statisticsTag() const {
return key().statisticsPeer(); return key().statisticsTag();
}
[[nodiscard]] FullMsgId statisticsContextId() const {
return key().statisticsContextId();
}
[[nodiscard]] FullStoryId statisticsStoryId() const {
return key().statisticsStoryId();
} }
[[nodiscard]] PollData *poll() const; [[nodiscard]] PollData *poll() const;
[[nodiscard]] FullMsgId pollContextId() const { [[nodiscard]] FullMsgId pollContextId() const {

View file

@ -290,7 +290,7 @@ Dialogs::RowDescriptor WrapWidget::activeChat() const {
} else if (key().settingsSelf() } else if (key().settingsSelf()
|| key().isDownloads() || key().isDownloads()
|| key().poll() || key().poll()
|| key().statisticsPeer()) { || key().statisticsTag().peer) {
return Dialogs::RowDescriptor(); return Dialogs::RowDescriptor();
} }
Unexpected("Owner in WrapWidget::activeChat()."); Unexpected("Owner in WrapWidget::activeChat().");

View 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

View file

@ -19,11 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Info::Statistics { namespace Info::Statistics {
Memento::Memento(not_null<Controller*> controller) Memento::Memento(not_null<Controller*> controller)
: ContentMemento(Tag{ : ContentMemento(controller->statisticsTag()) {
controller->statisticsPeer(),
controller->statisticsContextId(),
controller->statisticsStoryId(),
}) {
} }
Memento::Memento(not_null<PeerData*> peer, FullMsgId contextId) Memento::Memento(not_null<PeerData*> peer, FullMsgId contextId)
@ -65,9 +61,9 @@ Widget::Widget(
object_ptr<InnerWidget>( object_ptr<InnerWidget>(
this, this,
controller, controller,
controller->statisticsPeer(), controller->statisticsTag().peer,
controller->statisticsContextId(), controller->statisticsTag().contextId,
controller->statisticsStoryId()))) { controller->statisticsTag().storyId))) {
_inner->showRequests( _inner->showRequests(
) | rpl::start_with_next([=](InnerWidget::ShowRequest request) { ) | rpl::start_with_next([=](InnerWidget::ShowRequest request) {
if (request.history) { if (request.history) {
@ -79,7 +75,7 @@ Widget::Widget(
controller->showPeerInfo(request.info); controller->showPeerInfo(request.info);
} else if (request.messageStatistic || request.storyStatistic) { } else if (request.messageStatistic || request.storyStatistic) {
controller->showSection(Make( controller->showSection(Make(
controller->statisticsPeer(), controller->statisticsTag().peer,
request.messageStatistic, request.messageStatistic,
request.storyStatistic)); request.storyStatistic));
} else if (const auto &s = request.story) { } else if (const auto &s = request.story) {
@ -92,7 +88,7 @@ Widget::Widget(
} }
}, _inner->lifetime()); }, _inner->lifetime());
_inner->scrollToRequests( _inner->scrollToRequests(
) | rpl::start_with_next([=](const Ui::ScrollToRequest &request) { ) | rpl::start_with_next([this](const Ui::ScrollToRequest &request) {
scrollTo(request); scrollTo(request);
}, _inner->lifetime()); }, _inner->lifetime());
} }
@ -102,9 +98,9 @@ bool Widget::showInternal(not_null<ContentMemento*> memento) {
} }
rpl::producer<QString> Widget::title() { rpl::producer<QString> Widget::title() {
return controller()->statisticsContextId() return controller()->statisticsTag().contextId
? tr::lng_stats_message_title() ? tr::lng_stats_message_title()
: controller()->statisticsStoryId() : controller()->statisticsTag().storyId
? tr::lng_stats_story_title() ? tr::lng_stats_story_title()
: tr::lng_stats_title(); : tr::lng_stats_title();
} }