diff --git a/lib/src/utils/commands_extension.dart b/lib/src/utils/commands_extension.dart index a5cf153b..d45e4c2a 100644 --- a/lib/src/utils/commands_extension.dart +++ b/lib/src/utils/commands_extension.dart @@ -190,6 +190,11 @@ extension CommandsClientExtension on Client { currentEventJson, ); }); + addCommand('discardsession', (CommandArgs args) async { + await encryption?.keyManager + ?.clearOrUseOutboundGroupSession(args.room.id, wipe: true); + return ''; + }); } } diff --git a/test/commands_test.dart b/test/commands_test.dart index d01180d8..f9b3b211 100644 --- a/test/commands_test.dart +++ b/test/commands_test.dart @@ -20,6 +20,7 @@ import 'dart:convert'; import 'package:test/test.dart'; +import 'package:olm/olm.dart' as olm; import 'package:matrix/matrix.dart'; import 'fake_client.dart'; import 'fake_matrix_api.dart'; @@ -28,6 +29,7 @@ void main() { group('Commands', () { Client client; Room room; + var olmEnabled = true; final getLastMessagePayload = ([String type = 'm.room.message', String stateKey]) { @@ -40,6 +42,12 @@ void main() { }; test('setupClient', () async { + try { + await olm.init(); + olm.get_library_version(); + } catch (e) { + olmEnabled = false; + } client = await getClient(); room = Room(id: '!1234:fakeServer.notExisting', client: client); room.setState(Event( @@ -249,6 +257,21 @@ void main() { }); }); + test('discardsession', () async { + if (olmEnabled) { + await client.encryption.keyManager.createOutboundGroupSession(room.id); + expect( + client.encryption.keyManager.getOutboundGroupSession(room.id) != + null, + true); + await room.sendTextEvent('/discardsession'); + expect( + client.encryption.keyManager.getOutboundGroupSession(room.id) != + null, + false); + } + }); + test('dispose client', () async { await client.dispose(closeDatabase: true); });