mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Merge pull request #721 from symphorien/hotlist
Implement a binding to go to a room with unread messages
This commit is contained in:
commit
d6eeaa1c04
3 changed files with 52 additions and 0 deletions
|
@ -120,6 +120,11 @@ Page {
|
|||
}
|
||||
}
|
||||
|
||||
Shortcut {
|
||||
sequence: "Alt+A"
|
||||
onActivated: Rooms.nextRoomWithActivity()
|
||||
}
|
||||
|
||||
Shortcut {
|
||||
sequence: "Ctrl+Down"
|
||||
onActivated: Rooms.nextRoom()
|
||||
|
|
|
@ -917,6 +917,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()
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue