From 93d904b1aea1cf6f07a30f380854b24b05fcd147 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Thu, 27 Jun 2019 09:44:37 +0200 Subject: [PATCH] [Event] Fix wrong id reference --- lib/src/Event.dart | 2 +- lib/src/Room.dart | 9 ++++----- lib/src/Timeline.dart | 5 +---- test/Timeline_test.dart | 8 ++++---- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/src/Event.dart b/lib/src/Event.dart index df01c68..011a151 100644 --- a/lib/src/Event.dart +++ b/lib/src/Event.dart @@ -137,7 +137,7 @@ class Event { } return Event( - jsonObj["id"], + jsonObj["event_id"], User.fromJson(jsonObj, room), ChatTime(jsonObj["origin_server_ts"]), stateKey: User(jsonObj["state_key"]), diff --git a/lib/src/Room.dart b/lib/src/Room.dart index 8b0db81..9a205ca 100644 --- a/lib/src/Room.dart +++ b/lib/src/Room.dart @@ -184,7 +184,7 @@ class Room { EventUpdate eventUpdate = EventUpdate(type: "timeline", roomID: id, eventType: type, content: { "type": type, - "id": messageID, + "event_id": messageID, "sender": client.userID, "status": 0, "origin_server_ts": now, @@ -202,7 +202,7 @@ class Room { // Send the text and on success, store and display a *sent* event. final dynamic res = await sendText(message, txid: messageID); - if (res is ErrorResponse) { + if (res is ErrorResponse || !(res["event_id"] is String)) { // On error, set status to -1 eventUpdate.content["status"] = -1; client.connection.onEvent.add(eventUpdate); @@ -210,14 +210,13 @@ class Room { client.store.storeEventUpdate(eventUpdate); }); } else { - final String newEventID = res["event_id"]; eventUpdate.content["status"] = 1; - eventUpdate.content["id"] = newEventID; + eventUpdate.content["event_id"] = res["event_id"]; client.connection.onEvent.add(eventUpdate); await client.store?.transaction(() { client.store.storeEventUpdate(eventUpdate); }); - return newEventID; + return res["event_id"]; } return null; } diff --git a/lib/src/Timeline.dart b/lib/src/Timeline.dart index 215d049..ab36ab0 100644 --- a/lib/src/Timeline.dart +++ b/lib/src/Timeline.dart @@ -57,7 +57,7 @@ class Timeline { if (events[i].content.containsKey("txid") && events[i].content["txid"] == eventUpdate.content["content"]["txid"] || - events[i].id == eventUpdate.content["id"] || + events[i].id == eventUpdate.content["event_id"] || (eventUpdate.content.containsKey("unsigned") && eventUpdate.content["unsigned"]["transaction_id"] is String && @@ -69,9 +69,6 @@ class Timeline { events[i] = Event.fromJson(eventUpdate.content, room); } } else { - if (!eventUpdate.content.containsKey("id")) - eventUpdate.content["id"] = eventUpdate.content["event_id"]; - User user = await room.client.store ?.getUser(matrixID: eventUpdate.content["sender"], room: room); if (user != null) { diff --git a/test/Timeline_test.dart b/test/Timeline_test.dart index 166858e..f1033f4 100644 --- a/test/Timeline_test.dart +++ b/test/Timeline_test.dart @@ -62,7 +62,7 @@ void main() { "content": {"msgtype": "m.text", "body": "Testcase"}, "sender": "@alice:example.com", "status": 2, - "id": "1", + "event_id": "1", "origin_server_ts": testTimeStamp })); @@ -75,7 +75,7 @@ void main() { "content": {"msgtype": "m.text", "body": "Testcase"}, "sender": "@alice:example.com", "status": 2, - "id": "2", + "event_id": "2", "origin_server_ts": testTimeStamp - 1000 })); @@ -116,7 +116,7 @@ void main() { "content": {"msgtype": "m.text", "body": "test"}, "sender": "@alice:example.com", "status": 2, - "id": "42", + "event_id": "42", "unsigned": {"transaction_id": "1234"}, "origin_server_ts": DateTime.now().millisecondsSinceEpoch })); @@ -140,7 +140,7 @@ void main() { "content": {"msgtype": "m.text", "body": "Testcase"}, "sender": "@alice:example.com", "status": 0, - "id": "abc", + "event_id": "abc", "origin_server_ts": testTimeStamp })); await new Future.delayed(new Duration(milliseconds: 50));