diff --git a/lib/src/utils/commands_extension.dart b/lib/src/utils/commands_extension.dart index 4167ae9f..731c52a2 100644 --- a/lib/src/utils/commands_extension.dart +++ b/lib/src/utils/commands_extension.dart @@ -98,6 +98,19 @@ extension CommandsClientExtension on Client { txid: args.txid, ); }); + addCommand('dm', (CommandArgs args) async { + final parts = args.msg.split(' '); + return await args.room.client.startDirectChat( + parts.first, + enableEncryption: !parts.any((part) => part == '--no-encryption'), + ); + }); + addCommand('create', (CommandArgs args) async { + final parts = args.msg.split(' '); + return await args.room.client.createGroupChat( + enableEncryption: !parts.any((part) => part == '--no-encryption'), + ); + }); addCommand('plain', (CommandArgs args) async { return await args.room.sendTextEvent( args.msg, diff --git a/test/commands_test.dart b/test/commands_test.dart index 1084db88..87e94918 100644 --- a/test/commands_test.dart +++ b/test/commands_test.dart @@ -274,6 +274,28 @@ void main() { }); }); + test('dm', () async { + FakeMatrixApi.calledEndpoints.clear(); + await room.sendTextEvent('/dm @alice:example.com --no-encryption'); + expect( + json.decode( + FakeMatrixApi.calledEndpoints['/client/r0/createRoom']?.first), + { + 'invite': ['@alice:example.com'], + 'is_direct': true, + 'preset': 'trusted_private_chat' + }); + }); + + test('create', () async { + FakeMatrixApi.calledEndpoints.clear(); + await room.sendTextEvent('/create @alice:example.com --no-encryption'); + expect( + json.decode( + FakeMatrixApi.calledEndpoints['/client/r0/createRoom']?.first), + {'preset': 'private_chat'}); + }); + test('discardsession', () async { if (olmEnabled) { await client.encryption?.keyManager.createOutboundGroupSession(room.id);