-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathadd-skills-to-room.ts
49 lines (42 loc) · 1.44 KB
/
add-skills-to-room.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { service } from '@ember/service';
import { APP_BOXEL_ROOM_SKILLS_EVENT_TYPE } from '@cardstack/runtime-common/matrix-constants';
import type * as BaseCommandModule from 'https://cardstack.com/base/command';
import HostBaseCommand from '../lib/host-base-command';
import type MatrixService from '../services/matrix-service';
export default class AddSkillsToRoomCommand extends HostBaseCommand<
typeof BaseCommandModule.AddSkillsToRoomInput
> {
@service declare private matrixService: MatrixService;
async getInputType() {
let commandModule = await this.loadCommandModule();
const { AddSkillsToRoomInput } = commandModule;
return AddSkillsToRoomInput;
}
protected async run(
input: BaseCommandModule.AddSkillsToRoomInput,
): Promise<undefined> {
let { matrixService } = this;
let { roomId, skills } = input;
let roomSkillEventIds = await matrixService.addSkillCardsToRoomHistory(
skills,
roomId,
{ includeComputeds: true, useAbsoluteURL: true },
);
await matrixService.updateStateEvent(
roomId,
APP_BOXEL_ROOM_SKILLS_EVENT_TYPE,
'',
async (oldContent: Record<string, any>) => {
return {
enabledEventIds: [
...new Set([
...(oldContent.enabledEventIds || []),
...roomSkillEventIds,
]),
],
disabledEventIds: [...(oldContent.disabledEventIds || [])],
};
},
);
}
}