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(