From 5d45c224a31e6142fff0c6c10ae82a96cd037f32 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Thu, 10 Sep 2020 09:50:02 +0200 Subject: [PATCH] fix: Mark pending events as failed on startup --- lib/src/database/database.dart | 1 + lib/src/database/database.g.dart | 9 +++++++++ lib/src/database/database.moor | 1 + 3 files changed, 11 insertions(+) diff --git a/lib/src/database/database.dart b/lib/src/database/database.dart index 81dff832..4da4f2dd 100644 --- a/lib/src/database/database.dart +++ b/lib/src/database/database.dart @@ -143,6 +143,7 @@ class Database extends _$Database { Future getClient(String name) async { final res = await dbGetClient(name).get(); if (res.isEmpty) return null; + await markPendingEventsAsError(res.first.clientId); return res.first; } diff --git a/lib/src/database/database.g.dart b/lib/src/database/database.g.dart index 283679e2..486d2a0e 100644 --- a/lib/src/database/database.g.dart +++ b/lib/src/database/database.g.dart @@ -6514,6 +6514,15 @@ abstract class _$Database extends GeneratedDatabase { readsFrom: {files}).map(_rowToDbFile); } + Future markPendingEventsAsError(int client_id) { + return customUpdate( + 'UPDATE events SET status = -1 WHERE client_id = :client_id AND status = 0', + variables: [Variable.withInt(client_id)], + updates: {events}, + updateKind: UpdateKind.update, + ); + } + @override Iterable get allTables => allSchemaEntities.whereType(); @override diff --git a/lib/src/database/database.moor b/lib/src/database/database.moor index 7ce44251..9f00534a 100644 --- a/lib/src/database/database.moor +++ b/lib/src/database/database.moor @@ -233,3 +233,4 @@ removeRoom: DELETE FROM rooms WHERE client_id = :client_id AND room_id = :room_i removeRoomEvents: DELETE FROM events WHERE client_id = :client_id AND room_id = :room_id; storeFile: INSERT OR REPLACE INTO files (mxc_uri, bytes, saved_at) VALUES (:mxc_uri, :bytes, :time); dbGetFile: SELECT * FROM files WHERE mxc_uri = :mxc_uri; +markPendingEventsAsError: UPDATE events SET status = -1 WHERE client_id = :client_id AND status = 0;