Added ability to create statistics info layer with story id.

This commit is contained in:
23rd 2023-11-17 04:59:20 +03:00 committed by John Preston
parent f88eee8047
commit 34d0dac351
11 changed files with 62 additions and 42 deletions

View file

@ -2283,7 +2283,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
if (channel->flags() & ChannelDataFlag::CanGetStatistics) { if (channel->flags() & ChannelDataFlag::CanGetStatistics) {
auto callback = crl::guard(controller, [=] { auto callback = crl::guard(controller, [=] {
controller->showSection( controller->showSection(
Info::Statistics::Make(channel, itemId)); Info::Statistics::Make(channel, itemId, {}));
}); });
_menu->addAction( _menu->addAction(
tr::lng_stats_title(tr::now), tr::lng_stats_title(tr::now),

View file

@ -17,12 +17,13 @@ namespace Info::Boosts {
Memento::Memento(not_null<Controller*> controller) Memento::Memento(not_null<Controller*> controller)
: ContentMemento(Info::Statistics::Tag{ : ContentMemento(Info::Statistics::Tag{
controller->statisticsPeer(), controller->statisticsPeer(),
{} {},
{},
}) { }) {
} }
Memento::Memento(not_null<PeerData*> peer) Memento::Memento(not_null<PeerData*> peer)
: ContentMemento(Info::Statistics::Tag{ peer, {} }) { : ContentMemento(Info::Statistics::Tag{ peer, {}, {} }) {
} }
Memento::~Memento() = default; Memento::~Memento() = default;

View file

@ -340,7 +340,11 @@ Key ContentMemento::key() const {
} 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 = statisticsPeer()) {
return Statistics::Tag{ peer, statisticsContextId() }; return Statistics::Tag{
peer,
statisticsContextId(),
statisticsStoryId(),
};
} else { } else {
return Downloads::Tag(); return Downloads::Tag();
} }
@ -379,7 +383,8 @@ ContentMemento::ContentMemento(Stories::Tag stories)
ContentMemento::ContentMemento(Statistics::Tag statistics) ContentMemento::ContentMemento(Statistics::Tag statistics)
: _statisticsPeer(statistics.peer) : _statisticsPeer(statistics.peer)
, _statisticsContextId(statistics.contextId) { , _statisticsContextId(statistics.contextId)
, _statisticsStoryId(statistics.storyId) {
} }
} // namespace Info } // namespace Info

View file

@ -202,6 +202,9 @@ public:
FullMsgId statisticsContextId() const { FullMsgId statisticsContextId() const {
return _statisticsContextId; return _statisticsContextId;
} }
FullStoryId statisticsStoryId() const {
return _statisticsStoryId;
}
PollData *poll() const { PollData *poll() const {
return _poll; return _poll;
} }
@ -248,6 +251,7 @@ private:
Stories::Tab _storiesTab = {}; Stories::Tab _storiesTab = {};
PeerData * const _statisticsPeer = nullptr; PeerData * const _statisticsPeer = nullptr;
const FullMsgId _statisticsContextId; const FullMsgId _statisticsContextId;
const FullStoryId _statisticsStoryId;
PollData * const _poll = nullptr; PollData * const _poll = nullptr;
const FullMsgId _pollContextId; const FullMsgId _pollContextId;

View file

@ -106,6 +106,13 @@ FullMsgId Key::statisticsContextId() const {
return {}; 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 {
if (const auto data = std::get_if<PollKey>(&_value)) { if (const auto data = std::get_if<PollKey>(&_value)) {
return data->poll; return data->poll;

View file

@ -58,13 +58,18 @@ struct Tag {
namespace Info::Statistics { namespace Info::Statistics {
struct Tag { struct Tag {
explicit Tag(not_null<PeerData*> peer, FullMsgId contextId) explicit Tag(
not_null<PeerData*> peer,
FullMsgId contextId,
FullStoryId storyId)
: peer(peer) : peer(peer)
, contextId(contextId) { , contextId(contextId)
, storyId(storyId) {
} }
not_null<PeerData*> peer; not_null<PeerData*> peer;
FullMsgId contextId; FullMsgId contextId;
FullStoryId storyId;
}; };
} // namespace Info::Statistics } // namespace Info::Statistics
@ -89,6 +94,7 @@ public:
Stories::Tab storiesTab() const; Stories::Tab storiesTab() const;
PeerData *statisticsPeer() const; PeerData *statisticsPeer() const;
FullMsgId statisticsContextId() const; FullMsgId statisticsContextId() const;
FullStoryId statisticsStoryId() const;
PollData *poll() const; PollData *poll() const;
FullMsgId pollContextId() const; FullMsgId pollContextId() const;
@ -194,6 +200,9 @@ public:
[[nodiscard]] FullMsgId statisticsContextId() const { [[nodiscard]] FullMsgId statisticsContextId() const {
return key().statisticsContextId(); 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 {
return key().pollContextId(); return key().pollContextId();

View file

@ -533,11 +533,13 @@ InnerWidget::InnerWidget(
QWidget *parent, QWidget *parent,
not_null<Controller*> controller, not_null<Controller*> controller,
not_null<PeerData*> peer, not_null<PeerData*> peer,
FullMsgId contextId) FullMsgId contextId,
FullStoryId storyId)
: VerticalLayout(parent) : VerticalLayout(parent)
, _controller(controller) , _controller(controller)
, _peer(peer) , _peer(peer)
, _contextId(contextId) { , _contextId(contextId)
, _storyId(storyId) {
} }
void InnerWidget::load() { void InnerWidget::load() {
@ -803,13 +805,5 @@ void InnerWidget::showFinished() {
_showFinished.fire({}); _showFinished.fire({});
} }
not_null<PeerData*> InnerWidget::peer() const {
return _peer;
}
FullMsgId InnerWidget::contextId() const {
return _contextId;
}
} // namespace Info::Statistics } // namespace Info::Statistics

View file

@ -38,10 +38,8 @@ public:
QWidget *parent, QWidget *parent,
not_null<Controller*> controller, not_null<Controller*> controller,
not_null<PeerData*> peer, not_null<PeerData*> peer,
FullMsgId contextId); FullMsgId contextId,
FullStoryId storyId);
[[nodiscard]] not_null<PeerData*> peer() const;
[[nodiscard]] FullMsgId contextId() const;
[[nodiscard]] rpl::producer<Ui::ScrollToRequest> scrollToRequests() const; [[nodiscard]] rpl::producer<Ui::ScrollToRequest> scrollToRequests() const;
[[nodiscard]] rpl::producer<ShowRequest> showRequests() const; [[nodiscard]] rpl::producer<ShowRequest> showRequests() const;
@ -59,6 +57,7 @@ private:
not_null<Controller*> _controller; not_null<Controller*> _controller;
not_null<PeerData*> _peer; not_null<PeerData*> _peer;
FullMsgId _contextId; FullMsgId _contextId;
FullStoryId _storyId;
std::vector<not_null<MessagePreview*>> _messagePreviews; std::vector<not_null<MessagePreview*>> _messagePreviews;

View file

@ -18,11 +18,16 @@ Memento::Memento(not_null<Controller*> controller)
: ContentMemento(Tag{ : ContentMemento(Tag{
controller->statisticsPeer(), controller->statisticsPeer(),
controller->statisticsContextId(), controller->statisticsContextId(),
controller->statisticsStoryId(),
}) { }) {
} }
Memento::Memento(not_null<PeerData*> peer, FullMsgId contextId) Memento::Memento(not_null<PeerData*> peer, FullMsgId contextId)
: ContentMemento(Tag{ peer, contextId }) { : ContentMemento(Tag{ peer, contextId, {} }) {
}
Memento::Memento(not_null<PeerData*> peer, FullStoryId storyId)
: ContentMemento(Tag{ peer, {}, storyId }) {
} }
Memento::~Memento() = default; Memento::~Memento() = default;
@ -57,7 +62,8 @@ Widget::Widget(
this, this,
controller, controller,
controller->statisticsPeer(), controller->statisticsPeer(),
controller->statisticsContextId()))) { controller->statisticsContextId(),
controller->statisticsStoryId()))) {
_inner->showRequests( _inner->showRequests(
) | rpl::start_with_next([=](InnerWidget::ShowRequest request) { ) | rpl::start_with_next([=](InnerWidget::ShowRequest request) {
if (request.history) { if (request.history) {
@ -70,7 +76,8 @@ Widget::Widget(
} else if (request.messageStatistic) { } else if (request.messageStatistic) {
controller->showSection(Make( controller->showSection(Make(
controller->statisticsPeer(), controller->statisticsPeer(),
request.messageStatistic)); request.messageStatistic,
{}));
} }
}, _inner->lifetime()); }, _inner->lifetime());
_inner->scrollToRequests( _inner->scrollToRequests(
@ -79,20 +86,12 @@ Widget::Widget(
}, _inner->lifetime()); }, _inner->lifetime());
} }
not_null<PeerData*> Widget::peer() const {
return _inner->peer();
}
FullMsgId Widget::contextId() const {
return _inner->contextId();
}
bool Widget::showInternal(not_null<ContentMemento*> memento) { bool Widget::showInternal(not_null<ContentMemento*> memento) {
return false; return false;
} }
rpl::producer<QString> Widget::title() { rpl::producer<QString> Widget::title() {
return _inner->contextId() return controller()->statisticsContextId()
? tr::lng_stats_message_title() ? tr::lng_stats_message_title()
: tr::lng_stats_title(); : tr::lng_stats_title();
} }
@ -131,11 +130,13 @@ void Widget::restoreState(not_null<Memento*> memento) {
std::shared_ptr<Info::Memento> Make( std::shared_ptr<Info::Memento> Make(
not_null<PeerData*> peer, not_null<PeerData*> peer,
FullMsgId contextId) { 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>( return std::make_shared<Info::Memento>(
std::vector<std::shared_ptr<ContentMemento>>( std::vector<std::shared_ptr<ContentMemento>>(1, std::move(memento)));
1,
std::make_shared<Memento>(peer, contextId)));
} }
} // namespace Info::Statistics } // namespace Info::Statistics

View file

@ -18,6 +18,7 @@ class Memento final : public ContentMemento {
public: public:
Memento(not_null<Controller*> controller); Memento(not_null<Controller*> controller);
Memento(not_null<PeerData*> peer, FullMsgId contextId); Memento(not_null<PeerData*> peer, FullMsgId contextId);
Memento(not_null<PeerData*> peer, FullStoryId storyId);
~Memento(); ~Memento();
object_ptr<ContentWidget> createWidget( object_ptr<ContentWidget> createWidget(
@ -44,9 +45,6 @@ public:
rpl::producer<bool> desiredShadowVisibility() const override; rpl::producer<bool> desiredShadowVisibility() const override;
void showFinished() override; void showFinished() override;
[[nodiscard]] not_null<PeerData*> peer() const;
[[nodiscard]] FullMsgId contextId() const;
void setInternalState( void setInternalState(
const QRect &geometry, const QRect &geometry,
not_null<Memento*> memento); not_null<Memento*> memento);
@ -63,6 +61,7 @@ private:
[[nodiscard]] std::shared_ptr<Info::Memento> Make( [[nodiscard]] std::shared_ptr<Info::Memento> Make(
not_null<PeerData*> peer, not_null<PeerData*> peer,
FullMsgId contextId); FullMsgId contextId,
FullStoryId storyId);
} // namespace Info::Statistics } // namespace Info::Statistics

View file

@ -1008,7 +1008,8 @@ void Filler::addViewStatistics() {
if (channel->flags() & ChannelDataFlag::CanGetStatistics) { if (channel->flags() & ChannelDataFlag::CanGetStatistics) {
_addAction(tr::lng_stats_title(tr::now), [=] { _addAction(tr::lng_stats_title(tr::now), [=] {
if (const auto strong = weak.get()) { if (const auto strong = weak.get()) {
controller->showSection(Info::Statistics::Make(peer, {})); using namespace Info;
controller->showSection(Statistics::Make(peer, {}, {}));
} }
}, &st::menuIconStats); }, &st::menuIconStats);
} }