Mark read marker when switching room.

This commit is contained in:
Black Hat 2018-11-02 19:05:15 +08:00
parent d53f7bc9bd
commit 87103fcb19
6 changed files with 52 additions and 24 deletions

View File

@ -47,6 +47,8 @@ Page {
source: parent source: parent
elevation: 4 elevation: 4
} }
onLeaveRoom: roomForm.saveReadMarker(room)
} }
RoomPanel { RoomPanel {

View File

@ -25,6 +25,8 @@ Rectangle {
inviteDialog.currentRoom = currentRoom inviteDialog.currentRoom = currentRoom
inviteDialog.open() inviteDialog.open()
} else { } else {
leaveRoom(enteredRoom)
enterRoom(currentRoom)
enteredRoom = currentRoom enteredRoom = currentRoom
} }
} }

View File

@ -25,6 +25,9 @@ Rectangle {
property bool miniMode: width == 64 property bool miniMode: width == 64
signal enterRoom(var room)
signal leaveRoom(var room)
color: MSettings.darkTheme ? "#323232" : "#f3f3f3" color: MSettings.darkTheme ? "#323232" : "#f3f3f3"
Label { Label {
@ -83,7 +86,8 @@ Rectangle {
bottomPadding: 0 bottomPadding: 0
placeholderText: "Search..." placeholderText: "Search..."
background: Item {} background: Item {
}
} }
} }
} }
@ -99,7 +103,8 @@ Rectangle {
boundsBehavior: Flickable.DragOverBounds boundsBehavior: Flickable.DragOverBounds
ScrollBar.vertical: ScrollBar {} ScrollBar.vertical: ScrollBar {
}
delegate: RoomListDelegate { delegate: RoomListDelegate {
width: parent.width width: parent.width
@ -120,7 +125,14 @@ Rectangle {
horizontalAlignment: miniMode ? Text.AlignHCenter : undefined horizontalAlignment: miniMode ? Text.AlignHCenter : undefined
} }
RoomContextMenu { id: roomContextMenu } RoomContextMenu {
id: roomContextMenu
} }
} }
} }
}
/*##^## Designer {
D{i:0;autoSize:true;height:480;width:640}
}
##^##*/

View File

@ -6,15 +6,13 @@ RoomPanelForm {
roomHeader.topic: currentRoom ? (currentRoom.topic).replace(/(\r\n\t|\n|\r\t)/gm,"") : "" roomHeader.topic: currentRoom ? (currentRoom.topic).replace(/(\r\n\t|\n|\r\t)/gm,"") : ""
sortedMessageEventModel.onModelReset: { sortedMessageEventModel.onModelReset: {
if (currentRoom) if (currentRoom) {
{
var lastScrollPosition = sortedMessageEventModel.mapFromSource(currentRoom.savedTopVisibleIndex()) var lastScrollPosition = sortedMessageEventModel.mapFromSource(currentRoom.savedTopVisibleIndex())
console.log("Scrolling to position", lastScrollPosition) console.log("Scrolling to position", lastScrollPosition)
messageListView.currentIndex = 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) currentRoom.getPreviousContent(100)
} }
console.log("Model timeline reset")
} }
messageListView { messageListView {
@ -25,11 +23,7 @@ RoomPanelForm {
currentRoom.getPreviousContent(50); currentRoom.getPreviousContent(50);
} }
onMovementEnded: { onMovementEnded: currentRoom.saveViewport(sortedMessageEventModel.mapToSource(messageListView.indexAt(messageListView.contentX, messageListView.contentY)), sortedMessageEventModel.mapToSource(largestVisibleIndex))
currentRoom.saveViewport(sortedMessageEventModel.mapToSource(messageListView.indexAt(messageListView.contentX, messageListView.contentY)), sortedMessageEventModel.mapToSource(largestVisibleIndex))
var newReadMarker = sortedMessageEventModel.get(largestVisibleIndex).eventId
if (newReadMarker) currentRoom.readMarkerEventId = newReadMarker
}
displaced: Transition { displaced: Transition {
NumberAnimation { NumberAnimation {
@ -45,6 +39,13 @@ RoomPanelForm {
function goToEvent(eventID) { function goToEvent(eventID) {
var index = messageEventModel.eventIDToIndex(eventID) var index = messageEventModel.eventIDToIndex(eventID)
if (index === -1) return if (index === -1) return
messageListView.currentIndex = -1
messageListView.currentIndex = sortedMessageEventModel.mapFromSource(index) messageListView.currentIndex = sortedMessageEventModel.mapFromSource(index)
} }
function saveReadMarker(room) {
var readMarker = sortedMessageEventModel.get(messageListView.largestVisibleIndex).eventId
if (!readMarker) return
room.readMarkerEventId = readMarker
}
} }

View File

@ -135,21 +135,30 @@ Item {
font.italic: true font.italic: true
} }
Label { RowLayout {
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
visible: readMarker === true && index !== 0 visible: readMarker === true && index !== 0
text: "And Now" Rectangle {
color: "white" Layout.fillWidth: true
verticalAlignment: Text.AlignVCenter Layout.preferredHeight: 2
leftPadding: 8
rightPadding: 8
topPadding: 4
bottomPadding: 4
background: Rectangle { color: Material.accent
color: MSettings.darkTheme ? "#484848" : "grey" }
Label {
text: "And Now"
color: Material.accent
verticalAlignment: Text.AlignVCenter
}
Rectangle {
Layout.fillWidth: true
Layout.preferredHeight: 2
color: Material.accent
} }
} }
} }

View File

@ -1,8 +1,8 @@
#ifndef SpectralUser_H #ifndef SpectralUser_H
#define SpectralUser_H #define SpectralUser_H
#include "user.h"
#include "room.h" #include "room.h"
#include "user.h"
#include <QObject> #include <QObject>
@ -17,7 +17,9 @@ class SpectralUser : public User {
QImage getAvatar() { return avatar(128); } QImage getAvatar() { return avatar(128); }
signals: 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 #endif // SpectralUser_H