From 87103fcb19c4db0711000b3a4f67a090ed856202 Mon Sep 17 00:00:00 2001 From: Black Hat Date: Fri, 2 Nov 2018 19:05:15 +0800 Subject: [PATCH] Mark read marker when switching room. --- imports/Spectral/Page/Room.qml | 2 ++ imports/Spectral/Panel/RoomListDelegate.qml | 2 ++ .../Spectral/Panel/RoomListPanelForm.ui.qml | 18 ++++++++++-- imports/Spectral/Panel/RoomPanel.qml | 19 ++++++------ imports/Spectral/Panel/RoomPanelForm.ui.qml | 29 ++++++++++++------- src/spectraluser.h | 6 ++-- 6 files changed, 52 insertions(+), 24 deletions(-) diff --git a/imports/Spectral/Page/Room.qml b/imports/Spectral/Page/Room.qml index 3cf6980..033555c 100644 --- a/imports/Spectral/Page/Room.qml +++ b/imports/Spectral/Page/Room.qml @@ -47,6 +47,8 @@ Page { source: parent elevation: 4 } + + onLeaveRoom: roomForm.saveReadMarker(room) } RoomPanel { diff --git a/imports/Spectral/Panel/RoomListDelegate.qml b/imports/Spectral/Panel/RoomListDelegate.qml index cce89c5..371d7aa 100644 --- a/imports/Spectral/Panel/RoomListDelegate.qml +++ b/imports/Spectral/Panel/RoomListDelegate.qml @@ -25,6 +25,8 @@ Rectangle { inviteDialog.currentRoom = currentRoom inviteDialog.open() } else { + leaveRoom(enteredRoom) + enterRoom(currentRoom) enteredRoom = currentRoom } } diff --git a/imports/Spectral/Panel/RoomListPanelForm.ui.qml b/imports/Spectral/Panel/RoomListPanelForm.ui.qml index 81566d1..b0b6307 100644 --- a/imports/Spectral/Panel/RoomListPanelForm.ui.qml +++ b/imports/Spectral/Panel/RoomListPanelForm.ui.qml @@ -25,6 +25,9 @@ Rectangle { property bool miniMode: width == 64 + signal enterRoom(var room) + signal leaveRoom(var room) + color: MSettings.darkTheme ? "#323232" : "#f3f3f3" Label { @@ -83,7 +86,8 @@ Rectangle { bottomPadding: 0 placeholderText: "Search..." - background: Item {} + background: Item { + } } } } @@ -99,7 +103,8 @@ Rectangle { boundsBehavior: Flickable.DragOverBounds - ScrollBar.vertical: ScrollBar {} + ScrollBar.vertical: ScrollBar { + } delegate: RoomListDelegate { width: parent.width @@ -120,7 +125,14 @@ Rectangle { horizontalAlignment: miniMode ? Text.AlignHCenter : undefined } - RoomContextMenu { id: roomContextMenu } + RoomContextMenu { + id: roomContextMenu + } } } } + +/*##^## Designer { + D{i:0;autoSize:true;height:480;width:640} +} + ##^##*/ diff --git a/imports/Spectral/Panel/RoomPanel.qml b/imports/Spectral/Panel/RoomPanel.qml index 3d2ca6f..d0b276c 100644 --- a/imports/Spectral/Panel/RoomPanel.qml +++ b/imports/Spectral/Panel/RoomPanel.qml @@ -6,15 +6,13 @@ RoomPanelForm { roomHeader.topic: currentRoom ? (currentRoom.topic).replace(/(\r\n\t|\n|\r\t)/gm,"") : "" sortedMessageEventModel.onModelReset: { - if (currentRoom) - { + if (currentRoom) { var lastScrollPosition = sortedMessageEventModel.mapFromSource(currentRoom.savedTopVisibleIndex()) console.log("Scrolling to position", lastScrollPosition) messageListView.currentIndex = lastScrollPosition - if (messageListView.contentY < messageListView.originY + 10 || currentRoom.timelineSize === 0) + if (messageListView.contentY < messageListView.originY + 10 || messageListView.contentHeight < messageListView.height || currentRoom.timelineSize === 0) currentRoom.getPreviousContent(100) } - console.log("Model timeline reset") } messageListView { @@ -25,11 +23,7 @@ RoomPanelForm { currentRoom.getPreviousContent(50); } - onMovementEnded: { - currentRoom.saveViewport(sortedMessageEventModel.mapToSource(messageListView.indexAt(messageListView.contentX, messageListView.contentY)), sortedMessageEventModel.mapToSource(largestVisibleIndex)) - var newReadMarker = sortedMessageEventModel.get(largestVisibleIndex).eventId - if (newReadMarker) currentRoom.readMarkerEventId = newReadMarker - } + onMovementEnded: currentRoom.saveViewport(sortedMessageEventModel.mapToSource(messageListView.indexAt(messageListView.contentX, messageListView.contentY)), sortedMessageEventModel.mapToSource(largestVisibleIndex)) displaced: Transition { NumberAnimation { @@ -45,6 +39,13 @@ RoomPanelForm { function goToEvent(eventID) { var index = messageEventModel.eventIDToIndex(eventID) if (index === -1) return + messageListView.currentIndex = -1 messageListView.currentIndex = sortedMessageEventModel.mapFromSource(index) } + + function saveReadMarker(room) { + var readMarker = sortedMessageEventModel.get(messageListView.largestVisibleIndex).eventId + if (!readMarker) return + room.readMarkerEventId = readMarker + } } diff --git a/imports/Spectral/Panel/RoomPanelForm.ui.qml b/imports/Spectral/Panel/RoomPanelForm.ui.qml index 410454b..e1d7bf3 100644 --- a/imports/Spectral/Panel/RoomPanelForm.ui.qml +++ b/imports/Spectral/Panel/RoomPanelForm.ui.qml @@ -135,21 +135,30 @@ Item { font.italic: true } - Label { + RowLayout { + Layout.fillWidth: true Layout.alignment: Qt.AlignHCenter visible: readMarker === true && index !== 0 - text: "And Now" - color: "white" - verticalAlignment: Text.AlignVCenter - leftPadding: 8 - rightPadding: 8 - topPadding: 4 - bottomPadding: 4 + Rectangle { + Layout.fillWidth: true + Layout.preferredHeight: 2 - background: Rectangle { - color: MSettings.darkTheme ? "#484848" : "grey" + color: Material.accent + } + + Label { + text: "And Now" + color: Material.accent + verticalAlignment: Text.AlignVCenter + } + + Rectangle { + Layout.fillWidth: true + Layout.preferredHeight: 2 + + color: Material.accent } } } diff --git a/src/spectraluser.h b/src/spectraluser.h index 9e38f1f..1cb7871 100644 --- a/src/spectraluser.h +++ b/src/spectraluser.h @@ -1,8 +1,8 @@ #ifndef SpectralUser_H #define SpectralUser_H -#include "user.h" #include "room.h" +#include "user.h" #include @@ -17,7 +17,9 @@ class SpectralUser : public User { QImage getAvatar() { return avatar(128); } signals: - void inheritedAvatarChanged(User* user, const Room* roomContext); // https://bugreports.qt.io/browse/QTBUG-7684 + void inheritedAvatarChanged( + User* user, + const Room* roomContext); // https://bugreports.qt.io/browse/QTBUG-7684 }; #endif // SpectralUser_H