[Event] Make delete function async

This commit is contained in:
Christian Pauly 2019-07-24 10:48:13 +02:00
parent 4e3c1b271b
commit de55c201fc
2 changed files with 7 additions and 4 deletions

View File

@ -171,10 +171,11 @@ class Event {
/// Removes this event if the status is < 1. This event will just be removed
/// from the database and the timelines. Returns false if not removed.
bool remove() {
Future<bool> remove() async {
if (status < 1) {
if (room.client.store != null)
room.client.store.db.rawDelete("DELETE FROM Events WHERE id=?", [id]);
await room.client.store.db
.rawDelete("DELETE FROM Events WHERE id=?", [id]);
room.client.connection.onEvent.add(EventUpdate(
roomID: room.id,

View File

@ -164,9 +164,11 @@ void main() {
test("remove", () async {
Event event = Event.fromJson(
jsonObj, Room(id: "1234", client: Client("testclient", debug: true)));
expect(event.remove(), false);
final bool removed1 = await event.remove();
event.status = 0;
expect(event.remove(), true);
final bool removed2 = await event.remove();
expect(removed1, false);
expect(removed2, true);
});
test("sendAgain", () async {