From 5402a332d2c120c8e3eb0bf1fe9dc76c65dde012 Mon Sep 17 00:00:00 2001 From: miruka Date: Thu, 4 Jun 2020 23:12:03 -0400 Subject: [PATCH] Fix updating read receipt - Find the last event that wasn't sent by us to update the marker to, instead of picking whichever is the most recent - Use the proper event ID instead of ID that could be a local echo - Wait for the current marker update request to complete before trying to send a new one --- src/gui/Pages/Chat/Timeline/EventList.qml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/gui/Pages/Chat/Timeline/EventList.qml b/src/gui/Pages/Chat/Timeline/EventList.qml index 17bb8677..afa01eaa 100644 --- a/src/gui/Pages/Chat/Timeline/EventList.qml +++ b/src/gui/Pages/Chat/Timeline/EventList.qml @@ -6,6 +6,7 @@ import QtQuick.Window 2.12 import Clipboard 0.1 import "../../.." import "../../../Base" +import "../../../PythonBridge" import "../../../ShortcutBundles" Rectangle { @@ -238,6 +239,8 @@ Rectangle { property bool canLoad: true property bool loading: false + property Future updateMarkerFuture: null + property bool ownEventsOnLeft: window.settings.ownMessagesOnLeftAboveWidth < 0 ? false : @@ -353,16 +356,28 @@ Rectangle { } Timer { - interval: window.settings.markRoomReadMsecDelay + interval: Math.max(100, window.settings.markRoomReadMsecDelay) running: + ! eventList.updateMarkerFuture && (chat.roomInfo.unreads || chat.roomInfo.highlights) && Qt.application.state === Qt.ApplicationActive && (eventList.contentY + eventList.height) > -50 onTriggered: { - const eventId = eventList.model.get(0).id - py.callCoro("update_room_read_marker", [chat.roomId, eventId]) + for (let i = 0; i < eventList.model.count; i++) { + const item = eventList.model.get(i) + + if (item.sender !== chat.userId) { + eventList.updateMarkerFuture = py.callCoro( + "update_room_read_marker", + [chat.roomId, item.event_id], + () => { eventList.updateMarkerFuture = null }, + () => { eventList.updateMarkerFuture = null }, + ) + return + } + } } }