Simplify read message logic with inverted timeline
This commit is contained in:
parent
5af6f6528b
commit
51d7e64992
@ -31,6 +31,7 @@ Item {
|
|||||||
running: timelineManager.isInitialSync
|
running: timelineManager.isInitialSync
|
||||||
height: 200
|
height: 200
|
||||||
width: 200
|
width: 200
|
||||||
|
z: 3
|
||||||
}
|
}
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
@ -48,8 +49,6 @@ Item {
|
|||||||
|
|
||||||
boundsBehavior: Flickable.StopAtBounds
|
boundsBehavior: Flickable.StopAtBounds
|
||||||
|
|
||||||
onVerticalOvershootChanged: contentY = contentY - verticalOvershoot
|
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
acceptedButtons: Qt.NoButton
|
acceptedButtons: Qt.NoButton
|
||||||
@ -60,18 +59,7 @@ Item {
|
|||||||
chat.contentY = chat.contentY - wheel.angleDelta.y
|
chat.contentY = chat.contentY - wheel.angleDelta.y
|
||||||
wheel.accepted = true
|
wheel.accepted = true
|
||||||
chat.forceLayout()
|
chat.forceLayout()
|
||||||
chat.updatePosition()
|
chat.returnToBounds()
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onModelChanged: {
|
|
||||||
if (model) {
|
|
||||||
currentIndex = model.currentIndex
|
|
||||||
if (model.currentIndex == count - 1) {
|
|
||||||
positionViewAtEnd()
|
|
||||||
} else {
|
|
||||||
positionViewAtIndex(model.currentIndex, ListView.End)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,37 +70,13 @@ Item {
|
|||||||
anchors.top: chat.top
|
anchors.top: chat.top
|
||||||
anchors.left: chat.right
|
anchors.left: chat.right
|
||||||
anchors.bottom: chat.bottom
|
anchors.bottom: chat.bottom
|
||||||
onPressedChanged: if (!pressed) chat.updatePosition()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
property bool atBottom: false
|
|
||||||
onCountChanged: {
|
|
||||||
if (atBottom) {
|
|
||||||
var newIndex = count - 1 // last index
|
|
||||||
positionViewAtEnd()
|
|
||||||
currentIndex = newIndex
|
|
||||||
model.currentIndex = newIndex
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onAtYBeginningChanged: if (atYBeginning) { chat.model.currentIndex = 0; chat.currentIndex = 0; }
|
|
||||||
|
|
||||||
function updatePosition() {
|
|
||||||
for (var y = chat.contentY + chat.height; y > chat.height; y -= 9) {
|
|
||||||
var i = chat.itemAt(100, y);
|
|
||||||
if (!i) continue;
|
|
||||||
if (!i.isFullyVisible()) continue;
|
|
||||||
chat.model.currentIndex = i.getIndex();
|
|
||||||
chat.currentIndex = i.getIndex()
|
|
||||||
atBottom = i.getIndex() == count - 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onMovementEnded: updatePosition()
|
|
||||||
|
|
||||||
spacing: 4
|
spacing: 4
|
||||||
verticalLayoutDirection: ListView.BottomToTop
|
verticalLayoutDirection: ListView.BottomToTop
|
||||||
|
|
||||||
|
onCountChanged: if (atYEnd) model.currentIndex = 0 // Mark last event as read, since we are at the bottom
|
||||||
|
|
||||||
delegate: Rectangle {
|
delegate: Rectangle {
|
||||||
// This would normally be previousSection, but our model's order is inverted.
|
// This would normally be previousSection, but our model's order is inverted.
|
||||||
property bool sectionBoundary: (ListView.nextSection != "" && ListView.nextSection !== ListView.section) || model.index === chat.count - 1
|
property bool sectionBoundary: (ListView.nextSection != "" && ListView.nextSection !== ListView.section) || model.index === chat.count - 1
|
||||||
@ -126,12 +90,6 @@ Item {
|
|||||||
id: timelinerow
|
id: timelinerow
|
||||||
y: section ? section.y + section.height : 0
|
y: section ? section.y + section.height : 0
|
||||||
}
|
}
|
||||||
function isFullyVisible() {
|
|
||||||
return height > 1 && (y - chat.contentY - 1) + height < chat.height
|
|
||||||
}
|
|
||||||
function getIndex() {
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
onSectionBoundaryChanged: {
|
onSectionBoundaryChanged: {
|
||||||
if (sectionBoundary) {
|
if (sectionBoundary) {
|
||||||
@ -147,6 +105,14 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binding {
|
||||||
|
target: chat.model
|
||||||
|
property: "currentIndex"
|
||||||
|
when: y + height > chat.contentY + chat.height && y < chat.contentY + chat.height
|
||||||
|
value: index
|
||||||
|
delayed: true
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
section {
|
section {
|
||||||
|
@ -516,7 +516,7 @@ TimelineModel::setCurrentIndex(int index)
|
|||||||
currentId = indexToId(index);
|
currentId = indexToId(index);
|
||||||
emit currentIndexChanged(index);
|
emit currentIndexChanged(index);
|
||||||
|
|
||||||
if (oldIndex < index && !pending.contains(currentId) &&
|
if ((oldIndex > index || oldIndex == -1) && !pending.contains(currentId) &&
|
||||||
ChatPage::instance()->isActiveWindow()) {
|
ChatPage::instance()->isActiveWindow()) {
|
||||||
readEvent(currentId.toStdString());
|
readEvent(currentId.toStdString());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user