2023-06-05 16:31:15 +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
|
|
|
|
*/
|
|
|
|
#include "info/stories/info_stories_widget.h"
|
|
|
|
|
|
|
|
#include "info/stories/info_stories_inner_widget.h"
|
|
|
|
#include "info/info_controller.h"
|
|
|
|
#include "info/info_memento.h"
|
|
|
|
#include "ui/widgets/scroll_area.h"
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
|
|
|
|
namespace Info::Stories {
|
|
|
|
|
|
|
|
Memento::Memento(not_null<Controller*> controller)
|
|
|
|
: ContentMemento(Tag{ controller->storiesPeer(), controller->storiesTab() })
|
|
|
|
, _media(controller) {
|
|
|
|
}
|
|
|
|
|
2023-06-07 15:56:38 +00:00
|
|
|
Memento::Memento(not_null<PeerData*> peer, Tab tab)
|
|
|
|
: ContentMemento(Tag{ peer, tab })
|
2023-06-05 16:31:15 +00:00
|
|
|
, _media(peer, 0, Media::Type::PhotoVideo) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Memento::~Memento() = default;
|
|
|
|
|
|
|
|
Section Memento::section() const {
|
|
|
|
return Section(Section::Type::Stories);
|
|
|
|
}
|
|
|
|
|
|
|
|
object_ptr<ContentWidget> Memento::createWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Controller*> controller,
|
|
|
|
const QRect &geometry) {
|
|
|
|
auto result = object_ptr<Widget>(parent, controller);
|
|
|
|
result->setInternalState(geometry, this);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget::Widget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Controller*> controller)
|
|
|
|
: ContentWidget(parent, controller) {
|
|
|
|
_inner = setInnerWidget(object_ptr<InnerWidget>(
|
|
|
|
this,
|
|
|
|
controller));
|
|
|
|
_inner->setScrollHeightValue(scrollHeightValue());
|
|
|
|
_inner->scrollToRequests(
|
|
|
|
) | rpl::start_with_next([this](Ui::ScrollToRequest request) {
|
|
|
|
scrollTo(request);
|
|
|
|
}, _inner->lifetime());
|
|
|
|
}
|
|
|
|
|
2023-06-07 15:56:38 +00:00
|
|
|
void Widget::setIsStackBottom(bool isStackBottom) {
|
|
|
|
ContentWidget::setIsStackBottom(isStackBottom);
|
|
|
|
_inner->setIsStackBottom(isStackBottom);
|
|
|
|
}
|
|
|
|
|
2023-06-05 16:31:15 +00:00
|
|
|
bool Widget::showInternal(not_null<ContentMemento*> memento) {
|
|
|
|
if (!controller()->validateMementoPeer(memento)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (auto storiesMemento = dynamic_cast<Memento*>(memento.get())) {
|
2023-06-07 15:56:38 +00:00
|
|
|
const auto tab = controller()->key().storiesTab();
|
|
|
|
if (storiesMemento->storiesTab() == tab) {
|
|
|
|
restoreState(storiesMemento);
|
|
|
|
return true;
|
|
|
|
}
|
2023-06-05 16:31:15 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::setInternalState(
|
|
|
|
const QRect &geometry,
|
|
|
|
not_null<Memento*> memento) {
|
|
|
|
setGeometry(geometry);
|
|
|
|
Ui::SendPendingMoveResizeEvents(this);
|
|
|
|
restoreState(memento);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<ContentMemento> Widget::doCreateMemento() {
|
|
|
|
auto result = std::make_shared<Memento>(controller());
|
|
|
|
saveState(result.get());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<SelectedItems> Widget::selectedListValue() const {
|
|
|
|
return _inner->selectedListValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::selectionAction(SelectionAction action) {
|
|
|
|
_inner->selectionAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<QString> Widget::title() {
|
2023-06-07 15:56:38 +00:00
|
|
|
return (controller()->key().storiesTab() == Tab::Archive)
|
|
|
|
? tr::lng_stories_archive_title()
|
|
|
|
: tr::lng_stories_my_title();
|
2023-06-05 16:31:15 +00:00
|
|
|
}
|
|
|
|
|
2023-06-07 15:56:38 +00:00
|
|
|
std::shared_ptr<Info::Memento> Make(not_null<PeerData*> peer, Tab tab) {
|
2023-06-05 16:31:15 +00:00
|
|
|
return std::make_shared<Info::Memento>(
|
|
|
|
std::vector<std::shared_ptr<ContentMemento>>(
|
|
|
|
1,
|
2023-06-07 15:56:38 +00:00
|
|
|
std::make_shared<Memento>(peer, tab)));
|
2023-06-05 16:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Info::Stories
|
|
|
|
|