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
elevation: 4
}
onLeaveRoom: roomForm.saveReadMarker(room)
}
RoomPanel {

View File

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

View File

@ -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}
}
##^##*/

View File

@ -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
}
}

View File

@ -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
}
}
}

View File

@ -1,8 +1,8 @@
#ifndef SpectralUser_H
#define SpectralUser_H
#include "user.h"
#include "room.h"
#include "user.h"
#include <QObject>
@ -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