diff --git a/Telegram/SourceFiles/boxes/peer_list_box.cpp b/Telegram/SourceFiles/boxes/peer_list_box.cpp index 7df89882fa..d3d089a322 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_box.cpp @@ -120,6 +120,9 @@ void PeerListBox::createMultiSelect() { content()->submitted(); }); _select->entity()->setQueryChangedCallback([=](const QString &query) { + if (_customQueryChangedCallback) { + _customQueryChangedCallback(query); + } searchQueryChanged(query); }); _select->entity()->setItemRemovedCallback([=](uint64 itemId) { @@ -138,6 +141,10 @@ void PeerListBox::createMultiSelect() { _select->moveToLeft(0, 0); } +void PeerListBox::appendQueryChangedCallback(Fn callback) { + _customQueryChangedCallback = std::move(callback); +} + void PeerListBox::setAddedTopScrollSkip(int skip) { _addedTopScrollSkip = skip; _scrollBottomFixed = false; diff --git a/Telegram/SourceFiles/boxes/peer_list_box.h b/Telegram/SourceFiles/boxes/peer_list_box.h index 05d1fddecf..f60c98135d 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.h +++ b/Telegram/SourceFiles/boxes/peer_list_box.h @@ -1137,6 +1137,8 @@ public: void showFinished() override; + void appendQueryChangedCallback(Fn); + protected: void prepare() override; void setInnerFocus() override; @@ -1174,6 +1176,7 @@ private: object_ptr> _select = { nullptr }; const std::shared_ptr _show; + Fn _customQueryChangedCallback; std::unique_ptr _controller; Fn _init; bool _scrollBottomFixed = false; diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 334a6fb760..24c1007f0e 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -2234,13 +2234,29 @@ QPointer ShowForwardMessagesBox( auto init = [=](not_null box) { controllerRaw->setSearchNoResultsText( tr::lng_bot_chats_not_found(tr::now)); + const auto lastFilterId = box->lifetime().make_state(0); const auto chatsFilters = Ui::AddChatFiltersTabsStrip( box, session, - [=](FilterId id) { applyFilter(box, id); }); + [=](FilterId id) { + *lastFilterId = id; + applyFilter(box, id); + }); chatsFilters->lower(); - chatsFilters->heightValue() | rpl::start_with_next([box](int h) { - box->setAddedTopScrollSkip(h); + rpl::combine( + chatsFilters->heightValue(), + rpl::producer([=](auto consumer) { + auto lifetime = rpl::lifetime(); + consumer.put_next(false); + box->appendQueryChangedCallback([=](const QString &q) { + const auto hasQuery = !q.isEmpty(); + applyFilter(box, hasQuery ? 0 : (*lastFilterId)); + consumer.put_next_copy(hasQuery); + }); + return lifetime; + }) + ) | rpl::start_with_next([box](int h, bool hasQuery) { + box->setAddedTopScrollSkip(hasQuery ? 0 : h); }, box->lifetime()); box->multiSelectHeightValue() | rpl::start_with_next([=](int h) { chatsFilters->moveToLeft(0, h);