diff --git a/TODO.md b/TODO.md index c90f6fb5..e06dba7c 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,7 @@ # TODO - add account number binds +- next room with unread/mention keybinds - revise pane collapse mode - fix escape keybinds (filter rooms, message selection) diff --git a/src/gui/Base/HListView.qml b/src/gui/Base/HListView.qml index 4e938c6e..f5a5f7b9 100644 --- a/src/gui/Base/HListView.qml +++ b/src/gui/Base/HListView.qml @@ -68,6 +68,9 @@ ListView { property int lastCheckedDelegateIndex: 0 property int selectedCount: Object.keys(checked).length + readonly property var currentIndexModel: + currentIndex === -1 ? null : model.get(currentIndex) + function check(...indices) { for (const i of indices) { diff --git a/src/gui/MainPane/RoomList.qml b/src/gui/MainPane/RoomList.qml index 65c44d19..9565cc7b 100644 --- a/src/gui/MainPane/RoomList.qml +++ b/src/gui/MainPane/RoomList.qml @@ -19,11 +19,9 @@ HListView { width: roomList.width filterActive: Boolean(filter) isCurrent: - currentIndex !== -1 && - ( - roomList.model.get(currentIndex).for_account || - roomList.model.get(currentIndex).id - ) === model.id + currentIndexModel && + (currentIndexModel.for_account || currentIndexModel.id) === + model.id } } @@ -40,6 +38,16 @@ HListView { property string filter: "" + + readonly property bool currentShouldBeAccount: + window.uiState.page === "Pages/AccountSettings/AccountSettings.qml" + readonly property bool currentShouldBeRoom: + window.uiState.page === "Pages/Chat/Chat.qml" + readonly property string wantedUserId: + window.uiState.pageProperties.userId || "" + readonly property string wantedRoomId: + window.uiState.pageProperties.roomId || "" + readonly property var accountIndice: { const accounts = {} @@ -95,6 +103,43 @@ HListView { } + function setCorrectCurrentItem() { + if (! currentShouldBeRoom && ! currentShouldBeAccount) { + currentIndex = -1 + return + } + + for (let i = 0; i < model.count; i++) { + const item = model.get(i) + + if (( + currentShouldBeRoom && + item.type === "Room" && + item.id === wantedRoomId && + item.for_account === wantedUserId + ) || ( + currentShouldBeAccount && + item.type === "Account" && + item.id === wantedRoomId && + item.for_account === wantedUserId + )) { + currentIndex = i + return + } + } + } + + + Timer { + // On startup, the account/room takes an unknown amount of time to + // arrive in the model, try to find it until then. + interval: 200 + running: currentIndex === -1 + repeat: true + triggeredOnStart: true + onTriggered: setCorrectCurrentItem() + } + Timer { id: showItemLimiter interval: 200