2023-04-26 19:06:54 +00:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
*/
|
2023-10-02 15:36:25 +00:00
|
|
|
#include "info/statistics/info_statistics_widget.h"
|
2023-04-26 19:06:54 +00:00
|
|
|
|
2023-12-06 18:27:33 +00:00
|
|
|
#include "data/data_session.h"
|
|
|
|
#include "data/data_stories.h"
|
2023-10-02 15:36:25 +00:00
|
|
|
#include "info/info_controller.h"
|
|
|
|
#include "info/info_memento.h"
|
2023-12-06 18:27:33 +00:00
|
|
|
#include "info/statistics/info_statistics_inner_widget.h"
|
2023-04-26 19:06:54 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2023-12-06 18:27:33 +00:00
|
|
|
#include "main/main_session.h"
|
2023-04-26 19:06:54 +00:00
|
|
|
|
2023-10-02 15:36:25 +00:00
|
|
|
namespace Info::Statistics {
|
2023-04-26 19:06:54 +00:00
|
|
|
|
2023-10-02 15:36:25 +00:00
|
|
|
Memento::Memento(not_null<Controller*> controller)
|
2023-10-08 20:17:45 +00:00
|
|
|
: ContentMemento(Tag{
|
|
|
|
controller->statisticsPeer(),
|
|
|
|
controller->statisticsContextId(),
|
2023-11-17 01:59:20 +00:00
|
|
|
controller->statisticsStoryId(),
|
2023-10-08 20:17:45 +00:00
|
|
|
}) {
|
2023-10-02 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
2023-10-08 20:17:45 +00:00
|
|
|
Memento::Memento(not_null<PeerData*> peer, FullMsgId contextId)
|
2023-11-17 01:59:20 +00:00
|
|
|
: ContentMemento(Tag{ peer, contextId, {} }) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Memento::Memento(not_null<PeerData*> peer, FullStoryId storyId)
|
|
|
|
: ContentMemento(Tag{ peer, {}, storyId }) {
|
2023-10-02 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Memento::~Memento() = default;
|
|
|
|
|
|
|
|
Section Memento::section() const {
|
|
|
|
return Section(Section::Type::Statistics);
|
|
|
|
}
|
|
|
|
|
2023-10-11 01:53:59 +00:00
|
|
|
void Memento::setState(SavedState state) {
|
|
|
|
_state = std::move(state);
|
2023-10-10 23:40:10 +00:00
|
|
|
}
|
|
|
|
|
2023-10-11 01:53:59 +00:00
|
|
|
SavedState Memento::state() {
|
|
|
|
return base::take(_state);
|
2023-10-10 23:40:10 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 15:36:25 +00:00
|
|
|
object_ptr<ContentWidget> Memento::createWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Controller*> controller,
|
|
|
|
const QRect &geometry) {
|
|
|
|
auto result = object_ptr<Widget>(parent, controller);
|
2023-10-10 23:40:10 +00:00
|
|
|
result->setInternalState(geometry, this);
|
2023-10-02 15:36:25 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget::Widget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Controller*> controller)
|
2023-10-10 22:24:24 +00:00
|
|
|
: ContentWidget(parent, controller)
|
|
|
|
, _inner(setInnerWidget(
|
|
|
|
object_ptr<InnerWidget>(
|
|
|
|
this,
|
|
|
|
controller,
|
|
|
|
controller->statisticsPeer(),
|
2023-11-17 01:59:20 +00:00
|
|
|
controller->statisticsContextId(),
|
|
|
|
controller->statisticsStoryId()))) {
|
2023-10-10 22:24:24 +00:00
|
|
|
_inner->showRequests(
|
|
|
|
) | rpl::start_with_next([=](InnerWidget::ShowRequest request) {
|
|
|
|
if (request.history) {
|
|
|
|
controller->showPeerHistory(
|
|
|
|
request.history.peer,
|
|
|
|
Window::SectionShow::Way::Forward,
|
|
|
|
request.history.msg);
|
|
|
|
} else if (request.info) {
|
|
|
|
controller->showPeerInfo(request.info);
|
2023-11-22 03:24:38 +00:00
|
|
|
} else if (request.messageStatistic || request.storyStatistic) {
|
2023-10-10 22:24:24 +00:00
|
|
|
controller->showSection(Make(
|
|
|
|
controller->statisticsPeer(),
|
2023-11-17 01:59:20 +00:00
|
|
|
request.messageStatistic,
|
2023-11-22 03:24:38 +00:00
|
|
|
request.storyStatistic));
|
2023-12-06 18:27:33 +00:00
|
|
|
} else if (const auto &s = request.story) {
|
|
|
|
if (const auto peer = controller->session().data().peer(s.peer)) {
|
|
|
|
controller->parentController()->openPeerStory(
|
|
|
|
peer,
|
|
|
|
s.story,
|
|
|
|
{ Data::StoriesContextSingle() });
|
|
|
|
}
|
2023-10-10 22:24:24 +00:00
|
|
|
}
|
|
|
|
}, _inner->lifetime());
|
|
|
|
_inner->scrollToRequests(
|
|
|
|
) | rpl::start_with_next([=](const Ui::ScrollToRequest &request) {
|
|
|
|
scrollTo(request);
|
|
|
|
}, _inner->lifetime());
|
|
|
|
}
|
2023-10-09 14:10:58 +00:00
|
|
|
|
2023-10-02 15:36:25 +00:00
|
|
|
bool Widget::showInternal(not_null<ContentMemento*> memento) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<QString> Widget::title() {
|
2023-11-17 01:59:20 +00:00
|
|
|
return controller()->statisticsContextId()
|
2023-10-08 20:17:45 +00:00
|
|
|
? tr::lng_stats_message_title()
|
2023-11-17 03:00:38 +00:00
|
|
|
: controller()->statisticsStoryId()
|
|
|
|
? tr::lng_stats_story_title()
|
2023-10-08 20:17:45 +00:00
|
|
|
: tr::lng_stats_title();
|
2023-10-02 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
2023-10-10 23:40:10 +00:00
|
|
|
void Widget::setInternalState(
|
|
|
|
const QRect &geometry,
|
|
|
|
not_null<Memento*> memento) {
|
|
|
|
setGeometry(geometry);
|
|
|
|
Ui::SendPendingMoveResizeEvents(this);
|
|
|
|
restoreState(memento);
|
|
|
|
}
|
|
|
|
|
2023-10-02 15:36:25 +00:00
|
|
|
rpl::producer<bool> Widget::desiredShadowVisibility() const {
|
|
|
|
return rpl::single<bool>(true);
|
2023-04-26 19:06:54 +00:00
|
|
|
}
|
2023-10-02 15:36:25 +00:00
|
|
|
|
|
|
|
void Widget::showFinished() {
|
2023-10-10 22:24:24 +00:00
|
|
|
_inner->showFinished();
|
2023-10-02 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<ContentMemento> Widget::doCreateMemento() {
|
|
|
|
auto result = std::make_shared<Memento>(controller());
|
2023-10-10 23:40:10 +00:00
|
|
|
saveState(result.get());
|
2023-10-02 15:36:25 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-10-10 23:40:10 +00:00
|
|
|
void Widget::saveState(not_null<Memento*> memento) {
|
|
|
|
memento->setScrollTop(scrollTopSave());
|
|
|
|
_inner->saveState(memento);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::restoreState(not_null<Memento*> memento) {
|
|
|
|
_inner->restoreState(memento);
|
|
|
|
scrollTopRestore(memento->scrollTop());
|
|
|
|
}
|
|
|
|
|
2023-10-08 20:17:45 +00:00
|
|
|
std::shared_ptr<Info::Memento> Make(
|
|
|
|
not_null<PeerData*> peer,
|
2023-11-17 01:59:20 +00:00
|
|
|
FullMsgId contextId,
|
|
|
|
FullStoryId storyId) {
|
|
|
|
const auto memento = storyId
|
|
|
|
? std::make_shared<Memento>(peer, storyId)
|
|
|
|
: std::make_shared<Memento>(peer, contextId);
|
2023-10-02 15:36:25 +00:00
|
|
|
return std::make_shared<Info::Memento>(
|
2023-11-17 01:59:20 +00:00
|
|
|
std::vector<std::shared_ptr<ContentMemento>>(1, std::move(memento)));
|
2023-10-02 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Info::Statistics
|
|
|
|
|