[Event] Fix wrong id reference

This commit is contained in:
Christian Pauly 2019-06-27 09:44:37 +02:00
parent 8f96088f09
commit 93d904b1ae
4 changed files with 10 additions and 14 deletions

View file

@ -137,7 +137,7 @@ class Event {
} }
return Event( return Event(
jsonObj["id"], jsonObj["event_id"],
User.fromJson(jsonObj, room), User.fromJson(jsonObj, room),
ChatTime(jsonObj["origin_server_ts"]), ChatTime(jsonObj["origin_server_ts"]),
stateKey: User(jsonObj["state_key"]), stateKey: User(jsonObj["state_key"]),

View file

@ -184,7 +184,7 @@ class Room {
EventUpdate eventUpdate = EventUpdate eventUpdate =
EventUpdate(type: "timeline", roomID: id, eventType: type, content: { EventUpdate(type: "timeline", roomID: id, eventType: type, content: {
"type": type, "type": type,
"id": messageID, "event_id": messageID,
"sender": client.userID, "sender": client.userID,
"status": 0, "status": 0,
"origin_server_ts": now, "origin_server_ts": now,
@ -202,7 +202,7 @@ class Room {
// Send the text and on success, store and display a *sent* event. // Send the text and on success, store and display a *sent* event.
final dynamic res = await sendText(message, txid: messageID); 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 // On error, set status to -1
eventUpdate.content["status"] = -1; eventUpdate.content["status"] = -1;
client.connection.onEvent.add(eventUpdate); client.connection.onEvent.add(eventUpdate);
@ -210,14 +210,13 @@ class Room {
client.store.storeEventUpdate(eventUpdate); client.store.storeEventUpdate(eventUpdate);
}); });
} else { } else {
final String newEventID = res["event_id"];
eventUpdate.content["status"] = 1; eventUpdate.content["status"] = 1;
eventUpdate.content["id"] = newEventID; eventUpdate.content["event_id"] = res["event_id"];
client.connection.onEvent.add(eventUpdate); client.connection.onEvent.add(eventUpdate);
await client.store?.transaction(() { await client.store?.transaction(() {
client.store.storeEventUpdate(eventUpdate); client.store.storeEventUpdate(eventUpdate);
}); });
return newEventID; return res["event_id"];
} }
return null; return null;
} }

View file

@ -57,7 +57,7 @@ class Timeline {
if (events[i].content.containsKey("txid") && if (events[i].content.containsKey("txid") &&
events[i].content["txid"] == events[i].content["txid"] ==
eventUpdate.content["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.containsKey("unsigned") &&
eventUpdate.content["unsigned"]["transaction_id"] eventUpdate.content["unsigned"]["transaction_id"]
is String && is String &&
@ -69,9 +69,6 @@ class Timeline {
events[i] = Event.fromJson(eventUpdate.content, room); events[i] = Event.fromJson(eventUpdate.content, room);
} }
} else { } else {
if (!eventUpdate.content.containsKey("id"))
eventUpdate.content["id"] = eventUpdate.content["event_id"];
User user = await room.client.store User user = await room.client.store
?.getUser(matrixID: eventUpdate.content["sender"], room: room); ?.getUser(matrixID: eventUpdate.content["sender"], room: room);
if (user != null) { if (user != null) {

View file

@ -62,7 +62,7 @@ void main() {
"content": {"msgtype": "m.text", "body": "Testcase"}, "content": {"msgtype": "m.text", "body": "Testcase"},
"sender": "@alice:example.com", "sender": "@alice:example.com",
"status": 2, "status": 2,
"id": "1", "event_id": "1",
"origin_server_ts": testTimeStamp "origin_server_ts": testTimeStamp
})); }));
@ -75,7 +75,7 @@ void main() {
"content": {"msgtype": "m.text", "body": "Testcase"}, "content": {"msgtype": "m.text", "body": "Testcase"},
"sender": "@alice:example.com", "sender": "@alice:example.com",
"status": 2, "status": 2,
"id": "2", "event_id": "2",
"origin_server_ts": testTimeStamp - 1000 "origin_server_ts": testTimeStamp - 1000
})); }));
@ -116,7 +116,7 @@ void main() {
"content": {"msgtype": "m.text", "body": "test"}, "content": {"msgtype": "m.text", "body": "test"},
"sender": "@alice:example.com", "sender": "@alice:example.com",
"status": 2, "status": 2,
"id": "42", "event_id": "42",
"unsigned": {"transaction_id": "1234"}, "unsigned": {"transaction_id": "1234"},
"origin_server_ts": DateTime.now().millisecondsSinceEpoch "origin_server_ts": DateTime.now().millisecondsSinceEpoch
})); }));
@ -140,7 +140,7 @@ void main() {
"content": {"msgtype": "m.text", "body": "Testcase"}, "content": {"msgtype": "m.text", "body": "Testcase"},
"sender": "@alice:example.com", "sender": "@alice:example.com",
"status": 0, "status": 0,
"id": "abc", "event_id": "abc",
"origin_server_ts": testTimeStamp "origin_server_ts": testTimeStamp
})); }));
await new Future.delayed(new Duration(milliseconds: 50)); await new Future.delayed(new Duration(milliseconds: 50));