From 88b9cdd3455c41e86455084d67061732b4aeb89e Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 25 Oct 2019 08:02:56 +0000 Subject: [PATCH] [Connection] Clean up receipts --- lib/src/Connection.dart | 10 ++++------ lib/src/Event.dart | 14 ++++++-------- test/Client_test.dart | 7 +++++-- test/Timeline_test.dart | 7 +++---- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/src/Connection.dart b/lib/src/Connection.dart index 9a9951b..189a39d 100644 --- a/lib/src/Connection.dart +++ b/lib/src/Connection.dart @@ -461,15 +461,13 @@ class Connection { break; } } - if (userTimestampMap[mxid].containsKey("ts")) { - if (receiptStateContent[eventID] == null) - receiptStateContent[eventID] = {"m.read": {}}; - else if (receiptStateContent[eventID]["m.read"] == null) - receiptStateContent[eventID]["m.read"] = {}; - receiptStateContent[eventID]["m.read"][mxid] = { + receiptStateContent[mxid] = { + "event_id": eventID, "ts": userTimestampMap[mxid]["ts"], }; + print( + "$mxid hat $eventID um ${userTimestampMap[mxid]["ts"]} gelesen!"); } } } diff --git a/lib/src/Event.dart b/lib/src/Event.dart index 7a73b06..c129528 100644 --- a/lib/src/Event.dart +++ b/lib/src/Event.dart @@ -101,15 +101,13 @@ class Event extends RoomState { /// Returns a list of [Receipt] instances for this event. List get receipts { - if (!(room.roomAccountData.containsKey("m.receipt") && - room.roomAccountData["m.receipt"].content.containsKey(eventId))) - return []; + if (!(room.roomAccountData.containsKey("m.receipt"))) return []; List receiptsList = []; - for (var entry in room - .roomAccountData["m.receipt"].content[eventId]["m.read"].entries) { - receiptsList.add(Receipt( - room.states[entry.key]?.asUser ?? User(entry.key), - ChatTime(entry.value["ts"]))); + for (var entry in room.roomAccountData["m.receipt"].content.entries) { + if (entry.value["event_id"] == eventId) + receiptsList.add(Receipt( + room.states[entry.key]?.asUser ?? User(entry.key), + ChatTime(entry.value["ts"]))); } return receiptsList; } diff --git a/test/Client_test.dart b/test/Client_test.dart index bb2de3f..22b6e0e 100644 --- a/test/Client_test.dart +++ b/test/Client_test.dart @@ -130,9 +130,12 @@ void main() { expect(matrix.roomList.rooms[1].roomAccountData.length, 3); expect( matrix.roomList.rooms[1].roomAccountData["m.receipt"] - .content["7365636s6r6432:example.com"]["m.read"] - ["@alice:example.com"]["ts"], + .content["@alice:example.com"]["ts"], 1436451550453); + expect( + matrix.roomList.rooms[1].roomAccountData["m.receipt"] + .content["@alice:example.com"]["event_id"], + "7365636s6r6432:example.com"); expect(matrix.roomList.rooms.length, 2); expect(matrix.roomList.rooms[1].canonicalAlias, "#famedlyContactDiscovery:${matrix.userID.split(":")[1]}"); diff --git a/test/Timeline_test.dart b/test/Timeline_test.dart index 970a8b1..b9ce645 100644 --- a/test/Timeline_test.dart +++ b/test/Timeline_test.dart @@ -103,10 +103,9 @@ void main() { room.roomAccountData["m.receipt"] = RoomAccountData.fromJson({ "type": "m.receipt", "content": { - "1": { - "m.read": { - "@alice:example.com": {"ts": 1436451550453} - } + "@alice:example.com": { + "event_id": "1", + "ts": 1436451550453, } }, "room_id": roomID,