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 '';
|
return '';
|
||||||
});
|
});
|
||||||
addCommand('markasdm', (CommandArgs args) async {
|
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);
|
await args.room.addToDirectChat(args.msg);
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -314,7 +314,7 @@ void main() {
|
||||||
|
|
||||||
test('markasdm', () async {
|
test('markasdm', () async {
|
||||||
FakeMatrixApi.calledEndpoints.clear();
|
FakeMatrixApi.calledEndpoints.clear();
|
||||||
await room.sendTextEvent('/markasdm @fakealice:example.com');
|
await room.sendTextEvent('/markasdm @test:fakeServer.notExisting');
|
||||||
expect(
|
expect(
|
||||||
json.decode(FakeMatrixApi
|
json.decode(FakeMatrixApi
|
||||||
.calledEndpoints[
|
.calledEndpoints[
|
||||||
|
|
@ -325,7 +325,7 @@ void main() {
|
||||||
json.decode(FakeMatrixApi
|
json.decode(FakeMatrixApi
|
||||||
.calledEndpoints[
|
.calledEndpoints[
|
||||||
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct']
|
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct']
|
||||||
?.first)?['@fakealice:example.com'],
|
?.first)?['@test:fakeServer.notExisting'],
|
||||||
['!1234:fakeServer.notExisting']);
|
['!1234:fakeServer.notExisting']);
|
||||||
expect(
|
expect(
|
||||||
json
|
json
|
||||||
|
|
@ -335,19 +335,12 @@ void main() {
|
||||||
?.first)
|
?.first)
|
||||||
.entries
|
.entries
|
||||||
.any((e) =>
|
.any((e) =>
|
||||||
e.key != '@fakealice:example.com' &&
|
e.key != '@test:fakeServer.notExisting' &&
|
||||||
e.key != '@alice:example.com' &&
|
e.key != '@alice:example.com' &&
|
||||||
e.value.contains('!1234:fakeServer.notExisting')),
|
e.value.contains('!1234:fakeServer.notExisting')),
|
||||||
false);
|
false);
|
||||||
|
|
||||||
FakeMatrixApi.calledEndpoints.clear();
|
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 {
|
test('markasgroup', () async {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue