diff --git a/lib/src/Timeline.dart b/lib/src/Timeline.dart index 81b55c8..215d049 100644 --- a/lib/src/Timeline.dart +++ b/lib/src/Timeline.dart @@ -37,8 +37,6 @@ class Timeline { final onTimelineUpdateCallback onUpdate; final onTimelineInsertCallback onInsert; - Set waitToReplace = {}; - StreamSubscription sub; Timeline({this.room, this.events, this.onUpdate, this.onInsert}) { @@ -52,20 +50,23 @@ class Timeline { // Is this event already in the timeline? if (eventUpdate.content["status"] == 1 || eventUpdate.content["status"] == -1 || - waitToReplace.contains(eventUpdate.content["id"])) { + (eventUpdate.content.containsKey("unsigned") && + eventUpdate.content["unsigned"]["transaction_id"] is String)) { int i; for (i = 0; i < events.length; i++) { if (events[i].content.containsKey("txid") && events[i].content["txid"] == eventUpdate.content["content"]["txid"] || - events[i].id == eventUpdate.content["id"]) break; + events[i].id == eventUpdate.content["id"] || + (eventUpdate.content.containsKey("unsigned") && + eventUpdate.content["unsigned"]["transaction_id"] + is String && + events[i].content["txid"] == + eventUpdate.content["unsigned"]["transaction_id"])) + break; } if (i < events.length) { events[i] = Event.fromJson(eventUpdate.content, room); - if (eventUpdate.content["content"]["txid"] is String) - waitToReplace.add(eventUpdate.content["id"]); - else - waitToReplace.remove(eventUpdate.content["id"]); } } else { if (!eventUpdate.content.containsKey("id")) diff --git a/lib/src/sync/EventUpdate.dart b/lib/src/sync/EventUpdate.dart index 725a711..4de7339 100644 --- a/lib/src/sync/EventUpdate.dart +++ b/lib/src/sync/EventUpdate.dart @@ -36,7 +36,7 @@ class EventUpdate { final String eventType; // The json payload of the content of this event. - final dynamic content; + final Map content; EventUpdate({this.eventType, this.roomID, this.type, this.content}); } diff --git a/test/Timeline_test.dart b/test/Timeline_test.dart index d30a49b..7e6cf30 100644 --- a/test/Timeline_test.dart +++ b/test/Timeline_test.dart @@ -115,6 +115,7 @@ void main() { "sender": "@alice:example.com", "status": 2, "id": "42", + "unsigned": {"transaction_id": "1234"}, "origin_server_ts": DateTime.now().millisecondsSinceEpoch }));