[Store] Fix storage for sending events.

This commit is contained in:
Christian Pauly 2019-06-27 09:25:25 +02:00
parent bb7a72fbf5
commit c7689419ea
2 changed files with 25 additions and 13 deletions

View file

@ -171,6 +171,8 @@ class Room {
Future<String> sendTextEvent(String message, {String txid = null}) async {
final String type = "m.room.message";
// Create new transaction id
String messageID;
final int now = DateTime.now().millisecondsSinceEpoch;
if (txid == null) {
@ -182,7 +184,7 @@ class Room {
EventUpdate eventUpdate =
EventUpdate(type: "timeline", roomID: id, eventType: type, content: {
"type": type,
"id": null,
"id": messageID,
"sender": client.userID,
"status": 0,
"origin_server_ts": now,

View file

@ -220,19 +220,29 @@ class Store {
}
// Save the event in the database
if ((status == 1 || status == -1) &&
eventUpdate.content["txid"] is String)
txn.rawUpdate("UPDATE Events SET status=?, id=?, WHERE id=?",
[status, eventContent["id"], eventUpdate.content["txid"]]);
else
txn.rawInsert(
"INSERT OR REPLACE INTO Events VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)", [
eventContent["event_id"],
chat_id,
eventContent["origin_server_ts"],
eventContent["sender"],
state_key,
eventContent["content"]["body"],
eventContent["type"],
json.encode(eventContent["content"]),
status
]);
txn.rawInsert(
"INSERT OR REPLACE INTO Events VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)", [
eventContent["event_id"],
chat_id,
eventContent["origin_server_ts"],
eventContent["sender"],
state_key,
eventContent["content"]["body"],
eventContent["type"],
json.encode(eventContent["content"]),
status
]);
// Is there a transaction id? Then delete the event with this id.
if (eventUpdate.content.containsKey("unsigned") &&
eventUpdate.content["unsigned"]["transaction_id"] is String)
txn.rawDelete("DELETE FROM Events WHERE id=?",
[eventUpdate.content["unsigned"]["transaction_id"]]);
}
if (type == "history") return null;