Moved out lambda to jump to near chats filters to static function.

This commit is contained in:
23rd 2025-03-09 00:13:23 +03:00 committed by John Preston
parent feaeef6482
commit 7da0124286
3 changed files with 35 additions and 23 deletions

View file

@ -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([=] {

View file

@ -3244,4 +3244,30 @@ SessionController::~SessionController() {
resetFakeUnreadWhileOpened();
}
bool CheckAndJumpToNearChatsFilter(
not_null<SessionController*> 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

View file

@ -757,4 +757,9 @@ void ActivateWindow(not_null<SessionController*> controller);
not_null<SessionController*> controller,
GifPauseReason level);
bool CheckAndJumpToNearChatsFilter(
not_null<SessionController*> controller,
bool isNext,
bool jump);
} // namespace Window