Merge branch 'krille/add-mark-as-dm-commands' into 'main'
feat: Add markasdm and markasgroup commands See merge request famedly/company/frontend/famedlysdk!1092
This commit is contained in:
commit
651abc7c14
|
|
@ -1235,17 +1235,21 @@ class Room {
|
|||
|
||||
/// Removes this room from all direct chat tags.
|
||||
Future<void> removeFromDirectChat() async {
|
||||
final directChats = client.directChats;
|
||||
if (directChats[directChatMatrixID] is List &&
|
||||
directChats[directChatMatrixID].contains(id)) {
|
||||
directChats[directChatMatrixID].remove(id);
|
||||
} else {
|
||||
return;
|
||||
} // Nothing to do here
|
||||
final directChats = client.directChats.copy();
|
||||
for (final k in directChats.keys) {
|
||||
if (directChats[k] is List && directChats[k].contains(id)) {
|
||||
directChats[k].remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
await client.setAccountDataPerRoom(
|
||||
directChats.removeWhere((_, v) => v is List && v.isEmpty);
|
||||
|
||||
if (directChats == client.directChats) {
|
||||
return;
|
||||
}
|
||||
|
||||
await client.setAccountData(
|
||||
client.userID!,
|
||||
id,
|
||||
'm.direct',
|
||||
directChats,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -219,6 +219,14 @@ extension CommandsClientExtension on Client {
|
|||
await clearCache();
|
||||
return '';
|
||||
});
|
||||
addCommand('markasdm', (CommandArgs args) async {
|
||||
await args.room.addToDirectChat(args.msg);
|
||||
return;
|
||||
});
|
||||
addCommand('markasgroup', (CommandArgs args) async {
|
||||
await args.room.removeFromDirectChat();
|
||||
return;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -312,7 +312,68 @@ void main() {
|
|||
}
|
||||
});
|
||||
|
||||
test('create', () async {
|
||||
test('markasdm', () async {
|
||||
FakeMatrixApi.calledEndpoints.clear();
|
||||
await room.sendTextEvent('/markasdm @fakealice:example.com');
|
||||
expect(
|
||||
json.decode(FakeMatrixApi
|
||||
.calledEndpoints[
|
||||
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct']
|
||||
?.first)?['@alice:example.com'],
|
||||
['!1234:fakeServer.notExisting']);
|
||||
expect(
|
||||
json.decode(FakeMatrixApi
|
||||
.calledEndpoints[
|
||||
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct']
|
||||
?.first)?['@fakealice:example.com'],
|
||||
['!1234:fakeServer.notExisting']);
|
||||
expect(
|
||||
json
|
||||
.decode(FakeMatrixApi
|
||||
.calledEndpoints[
|
||||
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct']
|
||||
?.first)
|
||||
.entries
|
||||
.any((e) =>
|
||||
e.key != '@fakealice:example.com' &&
|
||||
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 {
|
||||
FakeMatrixApi.calledEndpoints.clear();
|
||||
await room.sendTextEvent('/markasgroup');
|
||||
expect(
|
||||
json
|
||||
.decode(FakeMatrixApi
|
||||
.calledEndpoints[
|
||||
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct']
|
||||
?.first)
|
||||
?.containsKey('@alice:example.com'),
|
||||
false);
|
||||
expect(
|
||||
json
|
||||
.decode(FakeMatrixApi
|
||||
.calledEndpoints[
|
||||
'/client/v3/user/%40test%3AfakeServer.notExisting/account_data/m.direct']
|
||||
?.first)
|
||||
.entries
|
||||
.any((e) => (e.value as List<dynamic>)
|
||||
.contains('!1234:fakeServer.notExisting')),
|
||||
false);
|
||||
});
|
||||
|
||||
test('clearcache', () async {
|
||||
await room.sendTextEvent('/clearcache');
|
||||
expect(room.client.prevBatch, null);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue