diff --git a/lib/src/database/hive_database.dart b/lib/src/database/hive_database.dart index 08e788a9..dd0d39d2 100644 --- a/lib/src/database/hive_database.dart +++ b/lib/src/database/hive_database.dart @@ -208,7 +208,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi { @override Future deleteFromToDeviceQueue(int clientId, int id) async { - await _toDeviceQueueBox.deleteAt(id); + await _toDeviceQueueBox.delete(id); return; } diff --git a/test/client_test.dart b/test/client_test.dart index b218bd0c..b5fcaa0e 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -523,6 +523,59 @@ void main() { bunnyContent); await client.dispose(closeDatabase: true); }); + test('send to_device queue multiple', () async { + // we test: + // send fox --> fail + // send raccoon --> fail + // send bunny --> all sent + final client = await getClient(); + FakeMatrixApi.failToDevice = true; + final foxContent = { + '@fox:example.org': { + '*': { + 'fox': 'hole', + }, + }, + }; + final raccoonContent = { + '@fox:example.org': { + '*': { + 'raccoon': 'mask', + }, + }, + }; + final bunnyContent = { + '@fox:example.org': { + '*': { + 'bunny': 'burrow', + }, + }, + }; + await client + .sendToDevice('foxies', 'floof_txnid', foxContent) + .catchError((e) => null); // ignore the error + await client + .sendToDevice('raccoon', 'raccoon_txnid', raccoonContent) + .catchError((e) => null); + FakeMatrixApi.failToDevice = false; + FakeMatrixApi.calledEndpoints.clear(); + await client.sendToDevice('bunny', 'bunny_txnid', bunnyContent); + expect( + json.decode(FakeMatrixApi + .calledEndpoints['/client/r0/sendToDevice/foxies/floof_txnid'] + [0])['messages'], + foxContent); + expect( + json.decode(FakeMatrixApi.calledEndpoints[ + '/client/r0/sendToDevice/raccoon/raccoon_txnid'][0])['messages'], + raccoonContent); + expect( + json.decode(FakeMatrixApi + .calledEndpoints['/client/r0/sendToDevice/bunny/bunny_txnid'] + [0])['messages'], + bunnyContent); + await client.dispose(closeDatabase: true); + }); test('Test the fake store api', () async { final database = await getDatabase(null); final client1 = Client(