From 2eab7044baa63bb9e3f65cdc846c8aad6ca2bf61 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sat, 12 Apr 2025 10:20:08 +0300 Subject: [PATCH] Added ability to emplace top bar suggestion later. --- .../SourceFiles/dialogs/dialogs_widget.cpp | 71 +++++++++++-------- Telegram/SourceFiles/dialogs/dialogs_widget.h | 2 + 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index dd3934622a..6ee40e1a69 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -379,36 +379,6 @@ Widget::Widget( OverscrollType::Real); const auto innerList = _scroll->setOwnedWidget( object_ptr(this)); - if (_layout != Layout::Child) { - TopBarSuggestionValue( - innerList, - &session() - ) | rpl::start_with_next([=](Ui::SlideWrap *raw) { - if (raw) { - _topBarSuggestion = innerList->insert( - 0, - object_ptr>::fromRaw(raw)); - rpl::combine( - _topBarSuggestion->entity()->desiredHeightValue(), - _childListShown.value() - ) | rpl::start_with_next([=]( - int desiredHeight, - float64 shown) { - const auto newHeight = desiredHeight * (1. - shown); - _topBarSuggestion->entity()->setMaximumHeight(newHeight); - _topBarSuggestion->entity()->setMinimumWidth((shown > 0) - ? width() - : 0); - _topBarSuggestion->entity()->resize(width(), newHeight); - }, _topBarSuggestion->lifetime()); - } else { - if (_topBarSuggestion) { - delete _topBarSuggestion; - } - _topBarSuggestion = nullptr; - } - }, lifetime()); - } _inner = innerList->add(object_ptr( innerList, controller, @@ -725,6 +695,7 @@ Widget::Widget( } setupFrozenAccountBar(); + setupTopBarSuggestions(innerList); } void Widget::setupSwipeBack() { @@ -1047,6 +1018,46 @@ void Widget::setupFrozenAccountBar() { }, lifetime()); } +void Widget::setupTopBarSuggestions(not_null dialogs) { + if (_layout == Layout::Child) { + return; + } + using namespace rpl::mappers; + crl::on_main(&session(), [=, session = &session()] { + (session->data().chatsListLoaded(nullptr) + ? rpl::single(nullptr) + : session->data().chatsListLoadedEvents() + ) | rpl::filter(_1 == nullptr) | rpl::map([=] { + return TopBarSuggestionValue(dialogs, session); + }) | rpl::flatten_latest() | rpl::start_with_next([=]( + Ui::SlideWrap *raw) { + if (raw) { + _topBarSuggestion = dialogs->insert( + 0, + object_ptr>::fromRaw(raw)); + rpl::combine( + _topBarSuggestion->entity()->desiredHeightValue(), + _childListShown.value() + ) | rpl::start_with_next([=]( + int desiredHeight, + float64 shown) { + const auto newHeight = desiredHeight * (1. - shown); + _topBarSuggestion->entity()->setMaximumHeight(newHeight); + _topBarSuggestion->entity()->setMinimumWidth((shown > 0) + ? width() + : 0); + _topBarSuggestion->entity()->resize(width(), newHeight); + }, _topBarSuggestion->lifetime()); + } else { + if (_topBarSuggestion) { + delete _topBarSuggestion; + } + _topBarSuggestion = nullptr; + } + }, lifetime()); + }); +} + void Widget::updateFrozenAccountBar() { if (_layout == Layout::Child || _openedForum diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.h b/Telegram/SourceFiles/dialogs/dialogs_widget.h index 2a6e8d4aca..fb502850fc 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.h @@ -55,6 +55,7 @@ template class FadeWrapScaled; template class SlideWrap; +class VerticalLayout; } // namespace Ui namespace Window { @@ -210,6 +211,7 @@ private: void setupShortcuts(); void setupStories(); void setupSwipeBack(); + void setupTopBarSuggestions(not_null dialogs); void storiesExplicitCollapse(); void collectStoriesUserpicsViews(Data::StorySourcesList list); void storiesToggleExplicitExpand(bool expand);