diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 42e67637b..39e047897 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -4893,33 +4893,14 @@ void InnerWidget::setupShortcuts() { }); } - const auto nearFolder = [=](bool isNext) { - const auto id = _controller->activeChatsFilterCurrent(); - const auto list = &session().data().chatsFilters().list(); - const auto index = int(ranges::find( - *list, - id, - &Data::ChatFilter::id - ) - begin(*list)); - if (index == list->size() && id != 0) { - return false; - } - const auto changed = index + (isNext ? 1 : -1); - if (changed >= int(list->size()) || changed < 0) { - return false; - } - _controller->setActiveChatsFilter((changed >= 0) - ? (*list)[changed].id() - : 0); - return true; - }; - request->check(Command::FolderNext) && request->handle([=] { - return nearFolder(true); + using namespace Window; + return CheckAndJumpToNearChatsFilter(_controller, true, true); }); request->check(Command::FolderPrevious) && request->handle([=] { - return nearFolder(false); + using namespace Window; + return CheckAndJumpToNearChatsFilter(_controller, false, true); }); request->check(Command::ReadChat) && request->handle([=] { diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 18783480e..e4fb08619 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -3244,4 +3244,30 @@ SessionController::~SessionController() { resetFakeUnreadWhileOpened(); } +bool CheckAndJumpToNearChatsFilter( + not_null controller, + bool isNext, + bool jump) { + const auto id = controller->activeChatsFilterCurrent(); + const auto list = &controller->session().data().chatsFilters().list(); + const auto index = int(ranges::find( + *list, + id, + &Data::ChatFilter::id + ) - begin(*list)); + if (index == list->size() && id != 0) { + return false; + } + const auto changed = index + (isNext ? 1 : -1); + if (changed >= int(list->size()) || changed < 0) { + return false; + } + if (jump) { + controller->setActiveChatsFilter((changed >= 0) + ? (*list)[changed].id() + : 0); + } + return true; +} + } // namespace Window diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index e4a53672e..afc847e3f 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -757,4 +757,9 @@ void ActivateWindow(not_null controller); not_null controller, GifPauseReason level); +bool CheckAndJumpToNearChatsFilter( + not_null controller, + bool isNext, + bool jump); + } // namespace Window