From 011cf3c652edc36ca5ebd95532623af3b2e412b3 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Sun, 3 Oct 2021 00:46:41 +0200 Subject: [PATCH] Fix highlighted room when opening room from notification --- imports/NeoChat/Page/RoomListPage.qml | 11 +++++++---- src/roomlistmodel.cpp | 5 +++++ src/roomlistmodel.h | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/imports/NeoChat/Page/RoomListPage.qml b/imports/NeoChat/Page/RoomListPage.qml index 9fb995e9f..20b78a017 100644 --- a/imports/NeoChat/Page/RoomListPage.qml +++ b/imports/NeoChat/Page/RoomListPage.qml @@ -39,6 +39,13 @@ Kirigami.ScrollablePage { onTriggered: page.contentItem.flickableItem.QQC2.ScrollBar.vertical.visible = !collapsedMode; } + Connections { + target: RoomManager + function onCurrentRoomChanged() { + itemSelection.setCurrentIndex(roomListModel.index(roomListModel.indexForRoom(RoomManager.currentRoom), 0), ItemSelectionModel.SelectCurrent) + } + } + function goToNextRoom() { do { listView.incrementCurrentIndex(); @@ -178,8 +185,6 @@ Kirigami.ScrollablePage { id: enterRoomAction onTriggered: { RoomManager.enterRoom(currentRoom); - itemSelection.setCurrentIndex(sortFilterRoomListModel.mapToSource( - sortFilterRoomListModel.index(index, 0)), ItemSelectionModel.SelectCurrent) } } Keys.onEnterPressed: enterRoomAction.trigger() @@ -224,8 +229,6 @@ Kirigami.ScrollablePage { id: enterRoomAction onTriggered: { RoomManager.enterRoom(currentRoom); - itemSelection.setCurrentIndex(sortFilterRoomListModel.mapToSource( - sortFilterRoomListModel.index(index, 0)), ItemSelectionModel.SelectCurrent) } } Keys.onEnterPressed: enterRoomAction.trigger() diff --git a/src/roomlistmodel.cpp b/src/roomlistmodel.cpp index 17511374b..a8ba81953 100644 --- a/src/roomlistmodel.cpp +++ b/src/roomlistmodel.cpp @@ -496,3 +496,8 @@ NeoChatRoom *RoomListModel::roomByAliasOrId(const QString &aliasOrId) } return nullptr; } + +int RoomListModel::indexForRoom(NeoChatRoom *room) const +{ + return m_rooms.indexOf(room); +} diff --git a/src/roomlistmodel.h b/src/roomlistmodel.h index eba679aa5..65d931cb0 100644 --- a/src/roomlistmodel.h +++ b/src/roomlistmodel.h @@ -73,6 +73,7 @@ public: Q_INVOKABLE [[nodiscard]] static QString categoryIconName(int section); Q_INVOKABLE void setCategoryVisible(int category, bool visible); Q_INVOKABLE [[nodiscard]] bool categoryVisible(int category) const; + Q_INVOKABLE [[nodiscard]] int indexForRoom(NeoChatRoom *room) const; [[nodiscard]] int notificationCount() const {