Merge pull request #1857 from famedly/td/mainThreadReceipts

fix: add main thread receipts to event.receipts getter
This commit is contained in:
td 2024-07-23 20:47:16 +05:30 committed by GitHub
commit c464032855
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 80 additions and 4 deletions

View File

@ -312,13 +312,27 @@ class Event extends MatrixEvent {
entry.value.timestamp))
.toList();
final own = receipts.global.latestOwnReceipt;
// add your own only once
final own = receipts.global.latestOwnReceipt ??
receipts.mainThread?.latestOwnReceipt;
if (own != null && own.eventId == eventId) {
receiptsList.add(Receipt(
room.unsafeGetUserFromMemoryOrFallback(room.client.userID!),
own.timestamp));
receiptsList.add(
Receipt(room.unsafeGetUserFromMemoryOrFallback(room.client.userID!),
own.timestamp),
);
}
// also add main thread. https://github.com/famedly/product-management/issues/1020
// also deduplicate.
receiptsList.addAll(receipts.mainThread?.otherUsers.entries
.where((entry) =>
entry.value.eventId == eventId &&
receiptsList.every((element) => element.user.id != entry.key))
.map((entry) => Receipt(
room.unsafeGetUserFromMemoryOrFallback(entry.key),
entry.value.timestamp)) ??
[]);
return receiptsList;
}

View File

@ -375,6 +375,68 @@ void main() {
expect(room.receiptState.byThread.length, 1);
expect(timeline.events[1].receipts.length, 2);
expect(timeline.events[1].receipts[0].user.id, '@bob:example.com');
// test receipt only on main thread
expect(timeline.events[2].receipts.length, 1);
await client.handleSync(SyncUpdate(
nextBatch: 'something5',
rooms: RoomsUpdate(join: {
timeline.room.id: JoinedRoomUpdate(ephemeral: [
BasicRoomEvent.fromJson({
'type': 'm.receipt',
'content': {
'\$2': {
'm.read': {
'@eve:example.com': {
'ts': 1436451550453,
'thread_id': 'main'
},
'@john:example.com': {
'ts': 1436451550453,
'thread_id': 'main'
},
},
},
},
})
])
})));
expect(room.receiptState.global.otherUsers['@eve:example.com']?.eventId,
null);
expect(
room.receiptState.mainThread?.otherUsers['@eve:example.com']?.eventId,
'\$2');
expect(timeline.events[1].receipts.length, 2);
expect(timeline.events[2].receipts.length, 3);
// test own receipt on main thread
await client.handleSync(SyncUpdate(
nextBatch: 'something6',
rooms: RoomsUpdate(join: {
timeline.room.id: JoinedRoomUpdate(ephemeral: [
BasicRoomEvent.fromJson({
'type': 'm.receipt',
'content': {
'\$2': {
'm.read': {
client.userID: {
'ts': 1436451550453,
'thread_id': 'main',
},
},
},
},
})
])
})));
expect(room.receiptState.global.latestOwnReceipt?.eventId, '\$1');
expect(room.receiptState.mainThread?.latestOwnReceipt?.eventId, '\$2');
expect(room.receiptState.global.ownPublic?.eventId, '\$2');
expect(room.receiptState.mainThread?.ownPublic?.eventId, '\$2');
expect(room.receiptState.global.ownPrivate?.eventId, '\$1');
expect(timeline.events[2].receipts.length, 3);
});
test('Sending both receipts at the same time sets the latest receipt',