Merge branch 'receipts-fix-clean-up' into 'master'

[Connection] Clean up receipts

See merge request famedly/famedlysdk!110
This commit is contained in:
Christian Pauly 2019-10-25 08:02:56 +00:00
commit 5904e7c8e6
4 changed files with 18 additions and 20 deletions

View file

@ -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!");
}
}
}

View file

@ -101,15 +101,13 @@ class Event extends RoomState {
/// Returns a list of [Receipt] instances for this event.
List<Receipt> get receipts {
if (!(room.roomAccountData.containsKey("m.receipt") &&
room.roomAccountData["m.receipt"].content.containsKey(eventId)))
return [];
if (!(room.roomAccountData.containsKey("m.receipt"))) return [];
List<Receipt> 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;
}

View file

@ -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]}");

View file

@ -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,