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.
This commit is contained in:
Christian Pauly 2022-02-15 10:18:18 +01:00
parent 788f8ea2a1
commit 01dfdb29fd
2 changed files with 10 additions and 1 deletions

View File

@ -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<String, dynamic>(client.userID!)
?.tryGet<int>('ts') ??
0;
return readAtMilliseconds < lastEvent.originServerTs.millisecondsSinceEpoch;
}
/// Returns true if this room is unread. To check if there are new messages

View File

@ -185,6 +185,7 @@ void main() {
stateKey: '',
),
);
expect(room.hasNewMessages, true);
expect(room.lastEvent?.body, 'cd');
room.setState(
Event(