fix: Check if argument is valid mxid in /maskasdm command
This commit is contained in:
parent
c5898f62b9
commit
31d4d5d08e
|
|
@ -220,6 +220,13 @@ extension CommandsClientExtension on Client {
|
|||
return '';
|
||||
});
|
||||
addCommand('markasdm', (CommandArgs args) async {
|
||||
final mxid = args.msg;
|
||||
if (!mxid.isValidMatrixId) {
|
||||
throw Exception('You must enter a valid mxid when using /maskasdm');
|
||||
}
|
||||
if (await args.room.requestUser(mxid, requestProfile: false) == null) {
|
||||
throw Exception('User $mxid is not in this room');
|
||||
}
|
||||
await args.room.addToDirectChat(args.msg);
|
||||
return;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -314,7 +314,7 @@ void main() {
|
|||
|
||||
test('markasdm', () async {
|
||||
FakeMatrixApi.calledEndpoints.clear();
|
||||
await room.sendTextEvent('/markasdm @fakealice:example.com');
|
||||
await room.sendTextEvent('/markasdm @test:fakeServer.notExisting');
|
||||
expect(
|
||||
json.decode(FakeMatrixApi
|
||||
.calledEndpoints[
|
||||
|
|
@ -325,7 +325,7 @@ void main() {
|
|||
json.decode(FakeMatrixApi
|
||||
.calledEndpoints[
|
||||
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct']
|
||||
?.first)?['@fakealice:example.com'],
|
||||
?.first)?['@test:fakeServer.notExisting'],
|
||||
['!1234:fakeServer.notExisting']);
|
||||
expect(
|
||||
json
|
||||
|
|
@ -335,19 +335,12 @@ void main() {
|
|||
?.first)
|
||||
.entries
|
||||
.any((e) =>
|
||||
e.key != '@fakealice:example.com' &&
|
||||
e.key != '@test:fakeServer.notExisting' &&
|
||||
e.key != '@alice:example.com' &&
|
||||
e.value.contains('!1234:fakeServer.notExisting')),
|
||||
false);
|
||||
|
||||
FakeMatrixApi.calledEndpoints.clear();
|
||||
await room.sendTextEvent('/markasdm');
|
||||
expect(
|
||||
json.decode(FakeMatrixApi
|
||||
.calledEndpoints[
|
||||
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct']
|
||||
?.first)?[''],
|
||||
['!1234:fakeServer.notExisting']);
|
||||
});
|
||||
|
||||
test('markasgroup', () async {
|
||||
|
|
|
|||
Loading…
Reference in New Issue