From 367d58c1ebe33633f739027e9169313178fdeff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Desgualdo=20Pereira?= Date: Sat, 13 Jun 2026 08:07:46 -0300 Subject: [PATCH] adds a new function and shortcut to cycle unread chats in reverse order, that is from oldest to newest --- src/uikeyconfig.cpp | 1 + src/uimodel.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++ src/uimodel.h | 1 + 3 files changed, 62 insertions(+) diff --git a/src/uikeyconfig.cpp b/src/uikeyconfig.cpp index e4d93564..53d59806 100644 --- a/src/uikeyconfig.cpp +++ b/src/uikeyconfig.cpp @@ -236,6 +236,7 @@ void UiKeyConfig::Init(bool p_MapKeys) { "next_chat", "KEY_TAB" }, { "prev_chat", "KEY_BTAB" }, { "unread_chat", "KEY_CTRLF" }, + { "unread_chat_reverse", "KEY_CTRLU" }, { "send_msg", "KEY_CTRLX" }, { "delete_msg", "KEY_CTRLD" }, { "delete_chat", "\\33\\144" }, // alt/opt-d diff --git a/src/uimodel.cpp b/src/uimodel.cpp index fd7dc409..7d5e0738 100644 --- a/src/uimodel.cpp +++ b/src/uimodel.cpp @@ -635,6 +635,60 @@ void UiModel::Impl::OnKeyUnreadChat() } } +void UiModel::Impl::OnKeyUnreadChatReverse() +{ + AnyUserKeyInput(); + + if (GetEditMessageActive()) return; + + if (m_ChatVec.empty()) return; + + std::vector unreadVec; + bool unreadIsSelected = false; + + // Populating from oldest to newest + for (ssize_t i = (ssize_t)m_ChatVec.size() - 1; i >= 0; --i) + { + const std::pair& chat = m_ChatVec.at(i); + const bool isUnread = GetChatIsUnread(chat.first, chat.second); + if (isUnread) + { + unreadVec.push_back(i); + if (m_CurrentChatIndex == (int)i) + { + unreadIsSelected = true; + } + } + } + + if (!unreadVec.empty()) + { + if (!unreadIsSelected) + { + m_CurrentChatIndex = unreadVec.at(0); + } + else if (unreadVec.size() > 1) + { + auto it = std::find(unreadVec.begin(), unreadVec.end(), m_CurrentChatIndex); + if (it != unreadVec.end()) + { + size_t idx = std::distance(unreadVec.begin(), it); + ++idx; + if (idx >= unreadVec.size()) + { + idx = 0; + } + + m_CurrentChatIndex = unreadVec.at(idx); + } + } + + m_CurrentChat = m_ChatVec.at(m_CurrentChatIndex); + OnCurrentChatChanged(); + SetSelectMessageActive(false); + } +} + void UiModel::Impl::OnKeyPrevPage() { AnyUserKeyInput(); @@ -4439,6 +4493,7 @@ void UiModel::KeyHandler(wint_t p_Key) static wint_t keyNextChat = UiKeyConfig::GetKey("next_chat"); static wint_t keyPrevChat = UiKeyConfig::GetKey("prev_chat"); static wint_t keyUnreadChat = UiKeyConfig::GetKey("unread_chat"); + static wint_t keyUnreadChatReverse = UiKeyConfig::GetKey("unread_chat_reverse"); static wint_t keyQuit = UiKeyConfig::GetKey("quit"); static wint_t keySelectEmoji = UiKeyConfig::GetKey("select_emoji"); @@ -4540,6 +4595,11 @@ void UiModel::KeyHandler(wint_t p_Key) std::unique_lock lock(m_ModelMutex); GetImpl().OnKeyUnreadChat(); } + else if (p_Key == keyUnreadChatReverse) + { + std::unique_lock lock(m_ModelMutex); + GetImpl().OnKeyUnreadChatReverse(); + } else if (p_Key == keyPrevPage) { std::unique_lock lock(m_ModelMutex); diff --git a/src/uimodel.h b/src/uimodel.h index d245d4aa..52f5c943 100644 --- a/src/uimodel.h +++ b/src/uimodel.h @@ -49,6 +49,7 @@ class UiModel void OnKeyNextChat(); void OnKeyPrevChat(); void OnKeyUnreadChat(); + void OnKeyUnreadChatReverse(); void OnKeyPrevPage(); void OnKeyNextPage(); bool OnKeyHomeFetchCache();