[Store] Fix storage for sending events.
This commit is contained in:
parent
bb7a72fbf5
commit
c7689419ea
|
|
@ -171,6 +171,8 @@ class Room {
|
||||||
|
|
||||||
Future<String> sendTextEvent(String message, {String txid = null}) async {
|
Future<String> sendTextEvent(String message, {String txid = null}) async {
|
||||||
final String type = "m.room.message";
|
final String type = "m.room.message";
|
||||||
|
|
||||||
|
// Create new transaction id
|
||||||
String messageID;
|
String messageID;
|
||||||
final int now = DateTime.now().millisecondsSinceEpoch;
|
final int now = DateTime.now().millisecondsSinceEpoch;
|
||||||
if (txid == null) {
|
if (txid == null) {
|
||||||
|
|
@ -182,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": null,
|
"id": messageID,
|
||||||
"sender": client.userID,
|
"sender": client.userID,
|
||||||
"status": 0,
|
"status": 0,
|
||||||
"origin_server_ts": now,
|
"origin_server_ts": now,
|
||||||
|
|
|
||||||
|
|
@ -220,7 +220,11 @@ class Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the event in the database
|
// 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(
|
txn.rawInsert(
|
||||||
"INSERT OR REPLACE INTO Events VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)", [
|
"INSERT OR REPLACE INTO Events VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)", [
|
||||||
eventContent["event_id"],
|
eventContent["event_id"],
|
||||||
|
|
@ -233,6 +237,12 @@ class Store {
|
||||||
json.encode(eventContent["content"]),
|
json.encode(eventContent["content"]),
|
||||||
status
|
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;
|
if (type == "history") return null;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue