Order the roomEvents models from newest to oldest
Qt somehow handles scrolling on new messages on its own when the ListView direction is bottom to top. In normal top to bottom, manual scrolling is completly buggy.
This commit is contained in:
@@ -5,8 +5,8 @@ Base.HLabel {
|
||||
text: date_time.toLocaleDateString()
|
||||
width: rootCol.width
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
topPadding: rootCol.isFirstMessage ? 0 : rootCol.verticalPadding * 4
|
||||
bottomPadding: rootCol.verticalPadding * 2
|
||||
topPadding: rootCol.isFirstMessage ? 0 : rootCol.standardSpacing
|
||||
bottomPadding: rootCol.standardSpacing
|
||||
font.pixelSize: normalSize * 1.1
|
||||
color: "darkolivegreen"
|
||||
}
|
||||
|
@@ -50,6 +50,7 @@ Row {
|
||||
|
||||
leftPadding: horizontalPadding
|
||||
rightPadding: horizontalPadding
|
||||
topPadding: nameLabel.visible ? 0 : verticalPadding
|
||||
bottomPadding: verticalPadding
|
||||
|
||||
Layout.minimumWidth: nameLabel.implicitWidth
|
||||
|
@@ -4,13 +4,20 @@ import QtQuick.Layouts 1.4
|
||||
import "../base" as Base
|
||||
|
||||
Column {
|
||||
id: rootCol
|
||||
id: "rootCol"
|
||||
|
||||
function mins_between(date1, date2) {
|
||||
console.log(Math.round((((date2 - date1) % 86400000) % 3600000) / 60000))
|
||||
return Math.round((((date2 - date1) % 86400000) % 3600000) / 60000)
|
||||
}
|
||||
|
||||
readonly property bool isMessage: type.startsWith("RoomMessage")
|
||||
function is_message(type_) { return type_.startsWith("RoomMessage") }
|
||||
|
||||
readonly property var previousItem:
|
||||
index < messageListView.model.count - 1 ?
|
||||
messageListView.model.get(index + 1) : null
|
||||
|
||||
readonly property bool isMessage: is_message(type)
|
||||
|
||||
readonly property bool isUndecryptableEvent:
|
||||
type === "OlmEvent" || type === "MegolmEvent"
|
||||
@@ -21,37 +28,38 @@ Column {
|
||||
readonly property bool isOwn:
|
||||
chatPage.user_id === dict.sender
|
||||
|
||||
readonly property var previousData:
|
||||
index > 0 ? messageListView.model.get(index - 1) : null
|
||||
|
||||
readonly property bool isFirstMessage: ! previousData
|
||||
readonly property bool isFirstMessage: ! previousItem
|
||||
|
||||
readonly property bool combine:
|
||||
! isFirstMessage &&
|
||||
previousData.isMessage === isMessage &&
|
||||
previousData.dict.sender === dict.sender &&
|
||||
mins_between(previousData.date_time, date_time) <= 5
|
||||
! talkBreak &&
|
||||
! dayBreak &&
|
||||
is_message(previousItem.type) === isMessage &&
|
||||
previousItem.dict.sender === dict.sender &&
|
||||
mins_between(previousItem.date_time, date_time) <= 5
|
||||
|
||||
readonly property bool dayBreak:
|
||||
isFirstMessage ||
|
||||
previousData.date_time.getDay() != date_time.getDay()
|
||||
date_time.getDay() != previousItem.date_time.getDay()
|
||||
|
||||
readonly property bool talkBreak:
|
||||
! isFirstMessage &&
|
||||
! dayBreak &&
|
||||
mins_between(previousData.date_time, date_time) >= 20
|
||||
mins_between(previousItem.date_time, date_time) >= 20
|
||||
|
||||
|
||||
property int standardSpacing: 8
|
||||
property int standardSpacing: 16
|
||||
property int horizontalPadding: 7
|
||||
property int verticalPadding: 5
|
||||
|
||||
width: parent.width
|
||||
topPadding:
|
||||
previousData === null ? 0 :
|
||||
talkBreak ? standardSpacing * 6 :
|
||||
combine ? standardSpacing / 2 :
|
||||
standardSpacing * 1.2
|
||||
! previousItem ? 0 :
|
||||
talkBreak ? standardSpacing * 3 :
|
||||
combine ? standardSpacing / 4 :
|
||||
standardSpacing
|
||||
|
||||
//Text { text: rootCol.topPadding }
|
||||
|
||||
Daybreak { visible: dayBreak }
|
||||
|
||||
|
@@ -13,18 +13,27 @@ Rectangle {
|
||||
ListView {
|
||||
id: messageListView
|
||||
anchors.fill: parent
|
||||
model: Backend.models.roomEvents.get(chatPage.room.room_id)
|
||||
delegate: MessageDelegate {}
|
||||
model: Backend.models.roomEvents.get(chatPage.room.room_id)
|
||||
//highlight: Rectangle {color: "lightsteelblue"; radius: 5}
|
||||
|
||||
clip: true
|
||||
topMargin: space
|
||||
bottomMargin: space
|
||||
verticalLayoutDirection: ListView.BottomToTop
|
||||
|
||||
// Keep x scroll pages cached, to limit images having to be
|
||||
// reloaded from network.
|
||||
cacheBuffer: height * 6
|
||||
|
||||
//Component.onCompleted: positionViewAtEnd()
|
||||
function goToEnd() {
|
||||
messageListView.positionViewAtEnd()
|
||||
//messageListView.flick(0, -messageListView.bottomMargin * 100)
|
||||
}
|
||||
|
||||
//Connections {
|
||||
//target: messageListView.model
|
||||
//onChanged: goToEnd()
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user