From 01dfdb29fd7725dbb18e097a5daceb57b90baa78 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Tue, 15 Feb 2022 10:18:18 +0100 Subject: [PATCH] fix: Has new messages compares ts This compares the origin server timestamp which might not map to the real sort order of the timeline. But it is the best solution for now. --- lib/src/room.dart | 10 +++++++++- test/room_test.dart | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/src/room.dart b/lib/src/room.dart index 759ec54b..02a59c3e 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -508,6 +508,8 @@ class Room { } /// Checks if the last event has a read marker of the user. + /// Warning: This compares the origin server timestamp which might not map + /// to the real sort order of the timeline. bool get hasNewMessages { final lastEvent = this.lastEvent; @@ -522,7 +524,13 @@ class Room { return false; } - return true; + final readAtMilliseconds = roomAccountData['m.receipt'] + ?.content + .tryGetMap(client.userID!) + ?.tryGet('ts') ?? + 0; + + return readAtMilliseconds < lastEvent.originServerTs.millisecondsSinceEpoch; } /// Returns true if this room is unread. To check if there are new messages diff --git a/test/room_test.dart b/test/room_test.dart index ffd49630..6b67186f 100644 --- a/test/room_test.dart +++ b/test/room_test.dart @@ -185,6 +185,7 @@ void main() { stateKey: '', ), ); + expect(room.hasNewMessages, true); expect(room.lastEvent?.body, 'cd'); room.setState( Event(