Skip to content

Commit

Permalink
fix: getSeenByUsers method to return exact receipts count
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian KOUNE committed Aug 28, 2023
1 parent 5b40bf1 commit 13fee92
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions lib/utils/room_status_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,28 @@ extension RoomStatusExtension on Room {
eventId ??= timeline.events.first.eventId;

final lastReceipts = <User>{};
// now we iterate the timeline events until we hit the first rendered event
for (final event in timeline.events) {
lastReceipts.addAll(event.receipts.map((r) => r.user));
if (event.eventId == eventId) {
break;

// mainThread.others only contains the last event of the room sent by the current user
if (receiptState.mainThread != null) {
final mainThreadReceipts = receiptState.mainThread!.otherUsers.entries
.where((element) => element.value.eventId == eventId)
.map((e) => unsafeGetUserFromMemoryOrFallback(e.key))
.toList();
lastReceipts.addAll(mainThreadReceipts);
} else {
// now we iterate the timeline events until we hit the first rendered event
for (final event in timeline.events) {
lastReceipts.addAll(event.receipts.map((r) => r.user));
if (event.eventId == eventId) {
break;
}
}
lastReceipts.removeWhere(
(user) =>
user.id == client.userID ||
user.id == timeline.events.first.senderId,
);
}
lastReceipts.removeWhere(
(user) =>
user.id == client.userID || user.id == timeline.events.first.senderId,
);
return lastReceipts.toList();
}
}

0 comments on commit 13fee92

Please sign in to comment.