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.
This commit is contained in:
Sorunome 2021-07-09 19:43:48 +02:00
parent 70763daec6
commit 4735d2d0a8
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
2 changed files with 54 additions and 1 deletions

View File

@ -208,7 +208,7 @@ class FamedlySdkHiveDatabase extends DatabaseApi {
@override @override
Future<void> deleteFromToDeviceQueue(int clientId, int id) async { Future<void> deleteFromToDeviceQueue(int clientId, int id) async {
await _toDeviceQueueBox.deleteAt(id); await _toDeviceQueueBox.delete(id);
return; return;
} }

View File

@ -523,6 +523,59 @@ void main() {
bunnyContent); bunnyContent);
await client.dispose(closeDatabase: true); 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 { test('Test the fake store api', () async {
final database = await getDatabase(null); final database = await getDatabase(null);
final client1 = Client( final client1 = Client(