diff --git a/lib/src/Event.dart b/lib/src/Event.dart index 02790fc..089603d 100644 --- a/lib/src/Event.dart +++ b/lib/src/Event.dart @@ -170,8 +170,8 @@ class Event { } /// Removes this event if the status is < 1. This event will just be removed - /// from the database and the timelines. - Future remove() async { + /// from the database and the timelines. Returns false if not removed. + bool remove() { if (status < 1) { if (room.client.store != null) room.client.store.db.rawDelete("DELETE FROM Events WHERE id=?", [id]); @@ -185,7 +185,9 @@ class Event { "status": -2, "content": {"body": "Removed..."} })); + return true; } + return false; } /// Try to send this event again. Only works with events of status -1. diff --git a/test/Event_test.dart b/test/Event_test.dart index 8a177e7..35270cb 100644 --- a/test/Event_test.dart +++ b/test/Event_test.dart @@ -23,10 +23,13 @@ import 'dart:convert'; +import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/src/Event.dart'; import 'package:famedlysdk/src/User.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'FakeMatrixApi.dart'; + void main() { /// All Tests related to the Event group("Event", () { @@ -157,5 +160,28 @@ void main() { event = Event.fromJson(jsonObj, null); expect(event.type, EventTypes.Reply); }); + + test("remove", () async { + Event event = Event.fromJson( + jsonObj, Room(id: "1234", client: Client("testclient", debug: true))); + expect(event.remove(), false); + event.status = 0; + expect(event.remove(), true); + }); + + test("sendAgain", () async { + Client matrix = Client("testclient", debug: true); + matrix.connection.httpClient = FakeMatrixApi(); + await matrix.checkServer("https://fakeServer.notExisting"); + await matrix.login("test", "1234"); + + Event event = Event.fromJson( + jsonObj, Room(id: "!1234:example.com", client: matrix)); + final String resp1 = await event.sendAgain(); + event.status = -1; + final String resp2 = await event.sendAgain(txid: "1234"); + expect(resp1, null); + expect(resp2, "42"); + }); }); }