summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-02-10 01:03:20 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2021-02-10 01:03:20 +0100
commitbdb6e6b79e9beeaabfbde99cd760de77247d11a4 (patch)
tree99978bd9bd0222606ea3a9ba74233bc18efb44d2 /src/timeline
parentAdd edit shortcuts and fix some focus stuff (diff)
downloadnheko-bdb6e6b79e9beeaabfbde99cd760de77247d11a4.tar.xz
Fix stuck notifications because of edits
Does not fix the read status yet, for that we need to compare read
receipts for all events after the last visible event.
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/TimelineModel.cpp23
-rw-r--r--src/timeline/TimelineModel.h2
2 files changed, 20 insertions, 5 deletions
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index de43d5ea..1163d931 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -740,10 +740,25 @@ TimelineModel::setCurrentIndex(int index)
 
         auto oldIndex = idToIndex(currentId);
         currentId     = indexToId(index);
-        emit currentIndexChanged(index);
-
-        if ((oldIndex > index || oldIndex == -1) && !currentId.startsWith("m")) {
-                readEvent(currentId.toStdString());
+        if (index != oldIndex)
+                emit currentIndexChanged(index);
+
+        if (!currentId.startsWith("m")) {
+                auto oldReadIndex =
+                  cache::getEventIndex(roomId().toStdString(), currentReadId.toStdString());
+                auto nextEventIndexAndId =
+                  cache::lastInvisibleEventAfter(roomId().toStdString(), currentId.toStdString());
+
+                if (nextEventIndexAndId &&
+                    (!oldReadIndex || *oldReadIndex < nextEventIndexAndId->first)) {
+                        readEvent(nextEventIndexAndId->second);
+                        currentReadId = QString::fromStdString(nextEventIndexAndId->second);
+
+                        nhlog::net()->info("Marked as read {}, index {}, oldReadIndex {}",
+                                           nextEventIndexAndId->second,
+                                           nextEventIndexAndId->first,
+                                           *oldReadIndex);
+                }
         }
 }
 
diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index 0aec27a1..017b6589 100644
--- a/src/timeline/TimelineModel.h
+++ b/src/timeline/TimelineModel.h
@@ -329,7 +329,7 @@ private:
         bool decryptDescription     = true;
         bool m_paginationInProgress = false;
 
-        QString currentId;
+        QString currentId, currentReadId;
         QString reply_, edit_;
         std::vector<QString> typingUsers_;