fix: Mark pending events as failed on startup

This commit is contained in:
Christian Pauly 2020-09-10 09:50:02 +02:00
parent aa9940fdbc
commit 5d45c224a3
3 changed files with 11 additions and 0 deletions

View file

@ -143,6 +143,7 @@ class Database extends _$Database {
Future<DbClient> getClient(String name) async {
final res = await dbGetClient(name).get();
if (res.isEmpty) return null;
await markPendingEventsAsError(res.first.clientId);
return res.first;
}

View file

@ -6514,6 +6514,15 @@ abstract class _$Database extends GeneratedDatabase {
readsFrom: {files}).map(_rowToDbFile);
}
Future<int> 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<TableInfo> get allTables => allSchemaEntities.whereType<TableInfo>();
@override

View file

@ -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;