summary refs log tree commit diff
diff options
context:
space:
mode:
authorDeepBlueV7.X <nicolas.werner@hotmail.de>2021-09-14 19:00:50 +0000
committerGitHub <noreply@github.com>2021-09-14 19:00:50 +0000
commitd6eeaa1c048e037b8ee40b2ee58946fc4bc5281e (patch)
treee855c3f48c696066e2992e2121b3c363b37c6951
parentAdd workaround for crash on some jdenticon inputs (diff)
parentadd Alt+A keybinding to switch to next room with unread messages (diff)
downloadnheko-d6eeaa1c048e037b8ee40b2ee58946fc4bc5281e.tar.xz
Merge pull request #721 from symphorien/hotlist
Implement a binding to go to a room with unread messages
-rw-r--r--resources/qml/Root.qml5
-rw-r--r--src/timeline/RoomlistModel.cpp46
-rw-r--r--src/timeline/RoomlistModel.h1
3 files changed, 52 insertions, 0 deletions
diff --git a/resources/qml/Root.qml b/resources/qml/Root.qml

index cc7d32ea..4207f35b 100644 --- a/resources/qml/Root.qml +++ b/resources/qml/Root.qml
@@ -121,6 +121,11 @@ Page { } Shortcut { + sequence: "Alt+A" + onActivated: Rooms.nextRoomWithActivity() + } + + Shortcut { sequence: "Ctrl+Down" onActivated: Rooms.nextRoom() } diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp
index afe53560..2d1dd49d 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp
@@ -918,6 +918,52 @@ FilteredRoomlistModel::toggleTag(QString roomid, QString tag, bool on) } void +FilteredRoomlistModel::nextRoomWithActivity() +{ + int roomWithMention = -1; + int roomWithNotification = -1; + int roomWithUnreadMessage = -1; + auto r = currentRoom(); + int currentRoomIdx = r ? roomidToIndex(r->roomId()) : -1; + // first look for mentions + for (int i = 0; i < (int)roomlistmodel->roomids.size(); i++) { + if (i == currentRoomIdx) + continue; + if (this->data(index(i, 0), RoomlistModel::HasLoudNotification).toBool()) { + roomWithMention = i; + break; + } + if (roomWithNotification == -1 && + this->data(index(i, 0), RoomlistModel::NotificationCount).toInt() > 0) { + roomWithNotification = i; + // don't break, we must continue looking for rooms with mentions + } + if (roomWithNotification == -1 && roomWithUnreadMessage == -1 && + this->data(index(i, 0), RoomlistModel::HasUnreadMessages).toBool()) { + roomWithUnreadMessage = i; + // don't break, we must continue looking for rooms with mentions + } + } + QString targetRoomId = nullptr; + if (roomWithMention != -1) { + targetRoomId = + this->data(index(roomWithMention, 0), RoomlistModel::RoomId).toString(); + nhlog::ui()->debug("choosing {} for mentions", targetRoomId.toStdString()); + } else if (roomWithNotification != -1) { + targetRoomId = + this->data(index(roomWithNotification, 0), RoomlistModel::RoomId).toString(); + nhlog::ui()->debug("choosing {} for notifications", targetRoomId.toStdString()); + } else if (roomWithUnreadMessage != -1) { + targetRoomId = + this->data(index(roomWithUnreadMessage, 0), RoomlistModel::RoomId).toString(); + nhlog::ui()->debug("choosing {} for unread messages", targetRoomId.toStdString()); + } + if (targetRoomId != nullptr) { + setCurrentRoom(targetRoomId); + } +} + +void FilteredRoomlistModel::nextRoom() { auto r = currentRoom(); diff --git a/src/timeline/RoomlistModel.h b/src/timeline/RoomlistModel.h
index c0a87aee..27c14bec 100644 --- a/src/timeline/RoomlistModel.h +++ b/src/timeline/RoomlistModel.h
@@ -172,6 +172,7 @@ public slots: void setCurrentRoom(QString roomid) { roomlistmodel->setCurrentRoom(std::move(roomid)); } void resetCurrentRoom() { roomlistmodel->resetCurrentRoom(); } + void nextRoomWithActivity(); void nextRoom(); void previousRoom();