summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-01-06 18:08:01 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2020-01-06 18:29:08 +0100
commit51d7e6499269af9106a8e36a25eb9ac1dfd8c57d (patch)
tree6fb2e636a83339398f808675887c130960a2ca68
parentUse fetchMore for native lazy loading of item model data (diff)
downloadnheko-51d7e6499269af9106a8e36a25eb9ac1dfd8c57d.tar.xz
Simplify read message logic with inverted timeline
-rw-r--r--resources/qml/TimelineView.qml58
-rw-r--r--src/timeline/TimelineModel.cpp2
2 files changed, 13 insertions, 47 deletions
diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml
index 18ae3793..0be8609d 100644
--- a/resources/qml/TimelineView.qml
+++ b/resources/qml/TimelineView.qml
@@ -31,6 +31,7 @@ Item {
 			running: timelineManager.isInitialSync
 			height: 200
 			width: 200
+			z: 3
 		}
 
 		ListView {
@@ -48,8 +49,6 @@ Item {
 
 			boundsBehavior: Flickable.StopAtBounds
 
-			onVerticalOvershootChanged: contentY = contentY - verticalOvershoot
-
 			MouseArea {
 				anchors.fill: parent
 				acceptedButtons: Qt.NoButton
@@ -60,18 +59,7 @@ Item {
 						chat.contentY = chat.contentY - wheel.angleDelta.y
 						wheel.accepted = true
 						chat.forceLayout()
-						chat.updatePosition()
-					}
-				}
-			}
-
-			onModelChanged: {
-				if (model) {
-					currentIndex = model.currentIndex
-					if (model.currentIndex == count - 1) {
-						positionViewAtEnd()
-					} else {
-						positionViewAtIndex(model.currentIndex, ListView.End)
+						chat.returnToBounds()
 					}
 				}
 			}
@@ -82,37 +70,13 @@ Item {
 				anchors.top: chat.top
 				anchors.left: chat.right
 				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
 			verticalLayoutDirection: ListView.BottomToTop
 
+			onCountChanged: if (atYEnd) model.currentIndex = 0 // Mark last event as read, since we are at the bottom
+
 			delegate: Rectangle {
 				// 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
@@ -126,12 +90,6 @@ Item {
 					id: timelinerow
 					y: section ? section.y + section.height : 0
 				}
-				function isFullyVisible() {
-					return height > 1 && (y - chat.contentY - 1) + height < chat.height
-				}
-				function getIndex() {
-					return index;
-				}
 
 				onSectionBoundaryChanged: {
 					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 {
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 3dafb8c2..0e7f5259 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -516,7 +516,7 @@ TimelineModel::setCurrentIndex(int index)
         currentId     = indexToId(index);
         emit currentIndexChanged(index);
 
-        if (oldIndex < index && !pending.contains(currentId) &&
+        if ((oldIndex > index || oldIndex == -1) && !pending.contains(currentId) &&
             ChatPage::instance()->isActiveWindow()) {
                 readEvent(currentId.toStdString());
         }