Merge branch 'krille/create-chat-commands' into 'main'

feat: Add commands to create chats

See merge request famedly/company/frontend/famedlysdk!903
This commit is contained in:
Sorunome 2021-11-21 12:48:30 +00:00
commit ffb4540172
2 changed files with 35 additions and 0 deletions

View File

@ -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,

View File

@ -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);