From 4735d2d0a8c6e2fc1e6f41f86b183f53791d7797 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Fri, 9 Jul 2021 19:43:48 +0200 Subject: [PATCH] fix: Sending of the to_device key With the switch to hive a regression of sending the to_device key was introduced: When popping elements .deleteAt(), so deleting at the index, was used, instead of .delete(), so deleting of the key. As the new events pushed onto the queue used hives auto increment key, a .delete() is appropriate here. --- lib/src/database/hive_database.dart | 2 +- test/client_test.dart | 53 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) 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(