mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Added second type of info layer for statistics.
This commit is contained in:
parent
3da733520d
commit
01821cd779
9 changed files with 85 additions and 11 deletions
|
@ -4066,6 +4066,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_stories_link_invalid" = "This link is broken or has expired.";
|
||||
|
||||
"lng_stats_title" = "Statistics";
|
||||
"lng_stats_message_title" = "Message Statistic";
|
||||
"lng_stats_zoom_out" = "Zoom Out";
|
||||
|
||||
"lng_stats_overview_title" = "Overview";
|
||||
|
|
|
@ -339,6 +339,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() };
|
||||
} else {
|
||||
return Downloads::Tag();
|
||||
}
|
||||
|
@ -375,4 +377,9 @@ ContentMemento::ContentMemento(Stories::Tag stories)
|
|||
, _storiesTab(stories.tab) {
|
||||
}
|
||||
|
||||
ContentMemento::ContentMemento(Statistics::Tag statistics)
|
||||
: _statisticsPeer(statistics.peer)
|
||||
, _statisticsContextId(statistics.contextId) {
|
||||
}
|
||||
|
||||
} // namespace Info
|
||||
|
|
|
@ -41,6 +41,10 @@ struct Tag;
|
|||
enum class Tab;
|
||||
} // namespace Info::Stories
|
||||
|
||||
namespace Info::Statistics {
|
||||
struct Tag;
|
||||
} // namespace Info::Statistics
|
||||
|
||||
namespace Info {
|
||||
|
||||
class ContentMemento;
|
||||
|
@ -163,6 +167,7 @@ public:
|
|||
explicit ContentMemento(Settings::Tag settings);
|
||||
explicit ContentMemento(Downloads::Tag downloads);
|
||||
explicit ContentMemento(Stories::Tag stories);
|
||||
explicit ContentMemento(Statistics::Tag statistics);
|
||||
ContentMemento(not_null<PollData*> poll, FullMsgId contextId)
|
||||
: _poll(poll)
|
||||
, _pollContextId(contextId) {
|
||||
|
@ -191,6 +196,12 @@ public:
|
|||
Stories::Tab storiesTab() const {
|
||||
return _storiesTab;
|
||||
}
|
||||
PeerData *statisticsPeer() const {
|
||||
return _statisticsPeer;
|
||||
}
|
||||
FullMsgId statisticsContextId() const {
|
||||
return _statisticsContextId;
|
||||
}
|
||||
PollData *poll() const {
|
||||
return _poll;
|
||||
}
|
||||
|
@ -235,6 +246,8 @@ private:
|
|||
UserData * const _settingsSelf = nullptr;
|
||||
PeerData * const _storiesPeer = nullptr;
|
||||
Stories::Tab _storiesTab = {};
|
||||
PeerData * const _statisticsPeer = nullptr;
|
||||
const FullMsgId _statisticsContextId;
|
||||
PollData * const _poll = nullptr;
|
||||
const FullMsgId _pollContextId;
|
||||
|
||||
|
|
|
@ -43,6 +43,9 @@ Key::Key(Downloads::Tag downloads) : _value(downloads) {
|
|||
Key::Key(Stories::Tag stories) : _value(stories) {
|
||||
}
|
||||
|
||||
Key::Key(Statistics::Tag statistics) : _value(statistics) {
|
||||
}
|
||||
|
||||
Key::Key(not_null<PollData*> poll, FullMsgId contextId)
|
||||
: _value(PollKey{ poll, contextId }) {
|
||||
}
|
||||
|
@ -89,6 +92,20 @@ Stories::Tab Key::storiesTab() const {
|
|||
return Stories::Tab();
|
||||
}
|
||||
|
||||
PeerData *Key::statisticsPeer() const {
|
||||
if (const auto tag = std::get_if<Statistics::Tag>(&_value)) {
|
||||
return tag->peer;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FullMsgId Key::statisticsContextId() const {
|
||||
if (const auto tag = std::get_if<Statistics::Tag>(&_value)) {
|
||||
return tag->contextId;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
PollData *Key::poll() const {
|
||||
if (const auto data = std::get_if<PollKey>(&_value)) {
|
||||
return data->poll;
|
||||
|
|
|
@ -55,6 +55,20 @@ struct Tag {
|
|||
|
||||
} // namespace Info::Stories
|
||||
|
||||
namespace Info::Statistics {
|
||||
|
||||
struct Tag {
|
||||
explicit Tag(not_null<PeerData*> peer, FullMsgId contextId)
|
||||
: peer(peer)
|
||||
, contextId(contextId) {
|
||||
}
|
||||
|
||||
not_null<PeerData*> peer;
|
||||
FullMsgId contextId;
|
||||
};
|
||||
|
||||
} // namespace Info::Statistics
|
||||
|
||||
namespace Info {
|
||||
|
||||
class Key {
|
||||
|
@ -64,6 +78,7 @@ public:
|
|||
Key(Settings::Tag settings);
|
||||
Key(Downloads::Tag downloads);
|
||||
Key(Stories::Tag stories);
|
||||
Key(Statistics::Tag statistics);
|
||||
Key(not_null<PollData*> poll, FullMsgId contextId);
|
||||
|
||||
PeerData *peer() const;
|
||||
|
@ -72,6 +87,8 @@ public:
|
|||
bool isDownloads() const;
|
||||
PeerData *storiesPeer() const;
|
||||
Stories::Tab storiesTab() const;
|
||||
PeerData *statisticsPeer() const;
|
||||
FullMsgId statisticsContextId() const;
|
||||
PollData *poll() const;
|
||||
FullMsgId pollContextId() const;
|
||||
|
||||
|
@ -86,6 +103,7 @@ private:
|
|||
Settings::Tag,
|
||||
Downloads::Tag,
|
||||
Stories::Tag,
|
||||
Statistics::Tag,
|
||||
PollKey> _value;
|
||||
|
||||
};
|
||||
|
@ -169,6 +187,12 @@ public:
|
|||
[[nodiscard]] Stories::Tab storiesTab() const {
|
||||
return key().storiesTab();
|
||||
}
|
||||
[[nodiscard]] PeerData *statisticsPeer() const {
|
||||
return key().statisticsPeer();
|
||||
}
|
||||
[[nodiscard]] FullMsgId statisticsContextId() const {
|
||||
return key().statisticsContextId();
|
||||
}
|
||||
[[nodiscard]] PollData *poll() const;
|
||||
[[nodiscard]] FullMsgId pollContextId() const {
|
||||
return key().pollContextId();
|
||||
|
|
|
@ -250,7 +250,10 @@ Dialogs::RowDescriptor WrapWidget::activeChat() const {
|
|||
storiesPeer->owner().history(storiesPeer),
|
||||
FullMsgId())
|
||||
: Dialogs::RowDescriptor();
|
||||
} else if (key().settingsSelf() || key().isDownloads() || key().poll()) {
|
||||
} else if (key().settingsSelf()
|
||||
|| key().isDownloads()
|
||||
|| key().poll()
|
||||
|| key().statisticsPeer()) {
|
||||
return Dialogs::RowDescriptor();
|
||||
}
|
||||
Unexpected("Owner in WrapWidget::activeChat().");
|
||||
|
|
|
@ -484,11 +484,14 @@ void FillRecentPosts(
|
|||
} // namespace
|
||||
|
||||
Memento::Memento(not_null<Controller*> controller)
|
||||
: Memento(controller->peer()) {
|
||||
: ContentMemento(Tag{
|
||||
controller->statisticsPeer(),
|
||||
controller->statisticsContextId(),
|
||||
}) {
|
||||
}
|
||||
|
||||
Memento::Memento(not_null<PeerData*> peer)
|
||||
: ContentMemento(peer, nullptr, {}) {
|
||||
Memento::Memento(not_null<PeerData*> peer, FullMsgId contextId)
|
||||
: ContentMemento(Tag{ peer, contextId }) {
|
||||
}
|
||||
|
||||
Memento::~Memento() = default;
|
||||
|
@ -509,7 +512,7 @@ Widget::Widget(
|
|||
QWidget *parent,
|
||||
not_null<Controller*> controller)
|
||||
: ContentWidget(parent, controller) {
|
||||
const auto peer = controller->peer();
|
||||
const auto peer = controller->statisticsPeer();
|
||||
if (!peer) {
|
||||
return;
|
||||
}
|
||||
|
@ -556,7 +559,9 @@ bool Widget::showInternal(not_null<ContentMemento*> memento) {
|
|||
}
|
||||
|
||||
rpl::producer<QString> Widget::title() {
|
||||
return tr::lng_stats_title();
|
||||
return controller()->key().statisticsContextId()
|
||||
? tr::lng_stats_message_title()
|
||||
: tr::lng_stats_title();
|
||||
}
|
||||
|
||||
rpl::producer<bool> Widget::desiredShadowVisibility() const {
|
||||
|
@ -572,11 +577,13 @@ std::shared_ptr<ContentMemento> Widget::doCreateMemento() {
|
|||
return result;
|
||||
}
|
||||
|
||||
std::shared_ptr<Info::Memento> Make(not_null<PeerData*> peer) {
|
||||
std::shared_ptr<Info::Memento> Make(
|
||||
not_null<PeerData*> peer,
|
||||
FullMsgId contextId) {
|
||||
return std::make_shared<Info::Memento>(
|
||||
std::vector<std::shared_ptr<ContentMemento>>(
|
||||
1,
|
||||
std::make_shared<Memento>(peer)));
|
||||
std::make_shared<Memento>(peer, contextId)));
|
||||
}
|
||||
|
||||
} // namespace Info::Statistics
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Info::Statistics {
|
|||
class Memento final : public ContentMemento {
|
||||
public:
|
||||
Memento(not_null<Controller*> controller);
|
||||
Memento(not_null<PeerData*> peer);
|
||||
Memento(not_null<PeerData*> peer, FullMsgId contextId);
|
||||
~Memento();
|
||||
|
||||
object_ptr<ContentWidget> createWidget(
|
||||
|
@ -42,6 +42,8 @@ private:
|
|||
|
||||
};
|
||||
|
||||
[[nodiscard]] std::shared_ptr<Info::Memento> Make(not_null<PeerData*> peer);
|
||||
[[nodiscard]] std::shared_ptr<Info::Memento> Make(
|
||||
not_null<PeerData*> peer,
|
||||
FullMsgId contextId);
|
||||
|
||||
} // namespace Info::Statistics
|
||||
|
|
|
@ -1007,7 +1007,7 @@ void Filler::addViewStatistics() {
|
|||
const auto peer = _peer;
|
||||
_addAction(tr::lng_stats_title(tr::now), [=] {
|
||||
if (const auto strong = weak.get()) {
|
||||
controller->showSection(Info::Statistics::Make(peer));
|
||||
controller->showSection(Info::Statistics::Make(peer, {}));
|
||||
}
|
||||
}, &st::menuIconStats);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue