2023-06-05 20:31:15 +04: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"
|
|
|
|
|
2024-12-12 12:11:39 +04:00
|
|
|
#include "data/data_peer.h"
|
2025-07-25 19:35:26 +04:00
|
|
|
#include "data/data_stories.h"
|
2023-06-05 20:31:15 +04:00
|
|
|
#include "info/stories/info_stories_inner_widget.h"
|
|
|
|
#include "info/info_controller.h"
|
|
|
|
#include "info/info_memento.h"
|
2025-08-01 18:24:12 +04:00
|
|
|
#include "ui/text/text_utilities.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
2023-06-05 20:31:15 +04:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
2025-08-01 18:24:12 +04:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2023-06-05 20:31:15 +04:00
|
|
|
#include "lang/lang_keys.h"
|
2024-08-28 14:12:19 +03:00
|
|
|
#include "ui/ui_utility.h"
|
2025-08-01 18:24:12 +04:00
|
|
|
#include "styles/style_info.h"
|
|
|
|
#include "styles/style_layers.h"
|
2023-06-05 20:31:15 +04:00
|
|
|
|
|
|
|
namespace Info::Stories {
|
|
|
|
|
2025-07-25 19:35:26 +04:00
|
|
|
int ArchiveId() {
|
|
|
|
return Data::kStoriesAlbumIdArchive;
|
|
|
|
}
|
|
|
|
|
2023-06-05 20:31:15 +04:00
|
|
|
Memento::Memento(not_null<Controller*> controller)
|
2025-07-25 19:35:26 +04:00
|
|
|
: ContentMemento(Tag{
|
|
|
|
controller->storiesPeer(),
|
2025-07-30 14:03:46 +04:00
|
|
|
controller->storiesAlbumId(),
|
|
|
|
controller->storiesAddToAlbumId() })
|
2023-06-05 20:31:15 +04:00
|
|
|
, _media(controller) {
|
|
|
|
}
|
|
|
|
|
2025-07-28 22:29:39 +04:00
|
|
|
Memento::Memento(not_null<PeerData*> peer, int albumId, int addingToAlbumId)
|
|
|
|
: ContentMemento(Tag{ peer, albumId, addingToAlbumId })
|
2023-06-05 20:31:15 +04: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)
|
2025-07-28 11:36:58 +04:00
|
|
|
: ContentWidget(parent, controller)
|
|
|
|
, _albumId(controller->key().storiesAlbumId()) {
|
2023-06-05 20:31:15 +04:00
|
|
|
_inner = setInnerWidget(object_ptr<InnerWidget>(
|
|
|
|
this,
|
2025-07-28 11:36:58 +04:00
|
|
|
controller,
|
2025-07-28 22:29:39 +04:00
|
|
|
_albumId.value(),
|
|
|
|
controller->key().storiesAddToAlbumId()));
|
2025-07-28 11:36:58 +04:00
|
|
|
_inner->albumIdChanges() | rpl::start_with_next([=](int id) {
|
|
|
|
controller->showSection(
|
|
|
|
Make(controller->storiesPeer(), id),
|
|
|
|
Window::SectionShow::Way::Backward);
|
|
|
|
}, _inner->lifetime());
|
2023-06-05 20:31:15 +04:00
|
|
|
_inner->setScrollHeightValue(scrollHeightValue());
|
|
|
|
_inner->scrollToRequests(
|
|
|
|
) | rpl::start_with_next([this](Ui::ScrollToRequest request) {
|
|
|
|
scrollTo(request);
|
|
|
|
}, _inner->lifetime());
|
2025-08-01 18:24:12 +04:00
|
|
|
|
|
|
|
_albumId.value() | rpl::start_with_next([=] {
|
|
|
|
refreshBottom();
|
|
|
|
}, _inner->lifetime());
|
2023-06-05 20:31:15 +04:00
|
|
|
}
|
|
|
|
|
2023-06-07 19:56:38 +04:00
|
|
|
void Widget::setIsStackBottom(bool isStackBottom) {
|
|
|
|
ContentWidget::setIsStackBottom(isStackBottom);
|
|
|
|
_inner->setIsStackBottom(isStackBottom);
|
|
|
|
}
|
|
|
|
|
2023-06-05 20:31:15 +04:00
|
|
|
bool Widget::showInternal(not_null<ContentMemento*> memento) {
|
|
|
|
if (!controller()->validateMementoPeer(memento)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (auto storiesMemento = dynamic_cast<Memento*>(memento.get())) {
|
2025-07-28 11:36:58 +04:00
|
|
|
const auto myId = controller()->key().storiesAlbumId();
|
|
|
|
const auto hisId = storiesMemento->storiesAlbumId();
|
|
|
|
constexpr auto kArchive = Data::kStoriesAlbumIdArchive;
|
|
|
|
if (myId == hisId) {
|
2023-06-07 19:56:38 +04:00
|
|
|
restoreState(storiesMemento);
|
|
|
|
return true;
|
2025-07-28 11:36:58 +04:00
|
|
|
} else if (myId != kArchive && hisId != kArchive) {
|
|
|
|
_albumId = hisId;
|
|
|
|
return true;
|
2023-06-07 19:56:38 +04:00
|
|
|
}
|
2023-06-05 20:31:15 +04: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());
|
|
|
|
}
|
|
|
|
|
2025-08-01 18:24:12 +04:00
|
|
|
void Widget::refreshBottom() {
|
|
|
|
const auto albumId = _albumId.current();
|
2025-08-11 19:25:01 +04:00
|
|
|
const auto withButton = (albumId != Data::kStoriesAlbumIdSaved)
|
|
|
|
&& (albumId != Data::kStoriesAlbumIdArchive)
|
2025-08-01 18:24:12 +04:00
|
|
|
&& controller()->storiesPeer()->canEditStories();
|
|
|
|
const auto wasBottom = _pinnedToBottom ? _pinnedToBottom->height() : 0;
|
|
|
|
delete _pinnedToBottom.data();
|
|
|
|
if (!withButton) {
|
|
|
|
setScrollBottomSkip(0);
|
|
|
|
_hasPinnedToBottom = false;
|
|
|
|
} else {
|
|
|
|
setupBottomButton(wasBottom, _inner->albumEmptyValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::setupBottomButton(
|
|
|
|
int wasBottomHeight,
|
|
|
|
rpl::producer<bool> hidden) {
|
|
|
|
_pinnedToBottom = Ui::CreateChild<Ui::SlideWrap<Ui::RpWidget>>(
|
|
|
|
this,
|
|
|
|
object_ptr<Ui::RpWidget>(this));
|
|
|
|
const auto wrap = _pinnedToBottom.data();
|
|
|
|
wrap->toggle(false, anim::type::instant);
|
|
|
|
|
|
|
|
const auto bottom = wrap->entity();
|
|
|
|
bottom->show();
|
|
|
|
|
|
|
|
const auto button = Ui::CreateChild<Ui::RoundButton>(
|
|
|
|
bottom,
|
|
|
|
rpl::single(QString()),
|
|
|
|
st::collectionEditBox.button);
|
|
|
|
button->setTextTransform(Ui::RoundButton::TextTransform::NoTransform);
|
|
|
|
button->setText(tr::lng_stories_album_add_button(
|
|
|
|
) | rpl::map([](const QString &text) {
|
|
|
|
return Ui::Text::IconEmoji(&st::collectionAddIcon).append(text);
|
|
|
|
}));
|
|
|
|
button->show();
|
|
|
|
std::move(hidden) | rpl::start_with_next([=](bool hidden) {
|
|
|
|
button->setVisible(!hidden);
|
|
|
|
_hasPinnedToBottom = !hidden;
|
|
|
|
}, button->lifetime());
|
|
|
|
|
|
|
|
button->setClickedCallback([=] {
|
|
|
|
if (const auto id = _albumId.current()) {
|
|
|
|
_inner->editAlbumStories(id);
|
|
|
|
} else {
|
|
|
|
refreshBottom();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const auto buttonTop = st::boxRadius;
|
|
|
|
bottom->widthValue() | rpl::start_with_next([=](int width) {
|
|
|
|
const auto normal = width - 2 * buttonTop;
|
|
|
|
button->resizeToWidth(normal);
|
|
|
|
const auto buttonLeft = (width - normal) / 2;
|
|
|
|
button->moveToLeft(buttonLeft, buttonTop);
|
|
|
|
}, button->lifetime());
|
|
|
|
|
|
|
|
button->heightValue() | rpl::start_with_next([=](int height) {
|
|
|
|
bottom->resize(bottom->width(), st::boxRadius + height);
|
|
|
|
}, button->lifetime());
|
|
|
|
|
|
|
|
const auto processHeight = [=] {
|
|
|
|
setScrollBottomSkip(wrap->height());
|
|
|
|
wrap->moveToLeft(wrap->x(), height() - wrap->height());
|
|
|
|
};
|
|
|
|
|
|
|
|
_inner->sizeValue(
|
|
|
|
) | rpl::start_with_next([=](const QSize &s) {
|
|
|
|
wrap->resizeToWidth(s.width());
|
|
|
|
crl::on_main(wrap, processHeight);
|
|
|
|
}, wrap->lifetime());
|
|
|
|
|
|
|
|
rpl::combine(
|
|
|
|
wrap->heightValue(),
|
|
|
|
heightValue()
|
|
|
|
) | rpl::start_with_next(processHeight, wrap->lifetime());
|
|
|
|
|
|
|
|
if (_shown) {
|
|
|
|
wrap->toggle(
|
|
|
|
true,
|
|
|
|
wasBottomHeight ? anim::type::instant : anim::type::normal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::showFinished() {
|
|
|
|
_shown = true;
|
|
|
|
if (const auto bottom = _pinnedToBottom.data()) {
|
|
|
|
bottom->toggle(true, anim::type::normal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-05 20:31:15 +04:00
|
|
|
rpl::producer<SelectedItems> Widget::selectedListValue() const {
|
|
|
|
return _inner->selectedListValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::selectionAction(SelectionAction action) {
|
|
|
|
_inner->selectionAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<QString> Widget::title() {
|
2024-12-12 12:11:39 +04:00
|
|
|
const auto peer = controller()->key().storiesPeer();
|
2025-07-25 19:35:26 +04:00
|
|
|
return (controller()->key().storiesAlbumId() == ArchiveId())
|
2023-06-07 19:56:38 +04:00
|
|
|
? tr::lng_stories_archive_title()
|
2024-12-12 12:11:39 +04:00
|
|
|
: (peer && peer->isSelf())
|
|
|
|
? tr::lng_menu_my_profile()
|
2023-06-07 19:56:38 +04:00
|
|
|
: tr::lng_stories_my_title();
|
2023-06-05 20:31:15 +04:00
|
|
|
}
|
|
|
|
|
2025-08-01 18:24:12 +04:00
|
|
|
rpl::producer<bool> Widget::desiredBottomShadowVisibility() {
|
|
|
|
return _hasPinnedToBottom.value();
|
|
|
|
}
|
|
|
|
|
2025-07-25 19:35:26 +04:00
|
|
|
std::shared_ptr<Info::Memento> Make(not_null<PeerData*> peer, int albumId) {
|
2023-06-05 20:31:15 +04:00
|
|
|
return std::make_shared<Info::Memento>(
|
|
|
|
std::vector<std::shared_ptr<ContentMemento>>(
|
|
|
|
1,
|
2025-07-28 22:29:39 +04:00
|
|
|
std::make_shared<Memento>(peer, albumId, 0)));
|
2023-06-05 20:31:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Info::Stories
|
|
|
|
|