mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-11 11:47:09 +02:00
Moved out lambda to jump to near chats filters to static function.
This commit is contained in:
parent
feaeef6482
commit
7da0124286
3 changed files with 35 additions and 23 deletions
|
@ -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([=] {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue