-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathExecuteViewClosedHandler.ts
More file actions
95 lines (90 loc) · 3.84 KB
/
Copy pathExecuteViewClosedHandler.ts
File metadata and controls
95 lines (90 loc) · 3.84 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import {
IHttp,
IModify,
IPersistence,
IRead,
} from "@rocket.chat/apps-engine/definition/accessors";
import { IApp } from "@rocket.chat/apps-engine/definition/IApp";
import { IRoom } from "@rocket.chat/apps-engine/definition/rooms";
import { UIKitViewCloseInteractionContext } from "@rocket.chat/apps-engine/definition/uikit";
import { ModalsEnum } from "../enum/Modals";
import { pullDetailsModal } from "../modals/pullDetailsModal";
import { storeInteractionRoomData, clearInteractionRoomData, getInteractionRoomData } from "../persistance/roomInteraction";
import { GithubSearchResultStorage } from "../persistance/searchResults";
import { GithubRepoIssuesStorage } from "../persistance/githubIssues";
export class ExecuteViewClosedHandler {
constructor(
private readonly app: IApp,
private readonly read: IRead,
private readonly http: IHttp,
private readonly modify: IModify,
private readonly persistence: IPersistence
) {}
public async run(context: UIKitViewCloseInteractionContext) {
const { view } = context.getInteractionData();
switch (view.id) {
case ModalsEnum.PULL_VIEW ||
ModalsEnum.CODE_VIEW:
const modal = await pullDetailsModal({
modify: this.modify,
read: this.read,
persistence: this.persistence,
http: this.http,
uikitcontext: context,
id: this.app.getID(),
});
await this.modify.getUiController().updateSurfaceView(
modal,
{
triggerId: context.getInteractionData()
.triggerId as string,
},
context.getInteractionData().user
);
break;
case ModalsEnum.SEARCH_RESULT_VIEW:{
const room = context.getInteractionData().room;
const user = context.getInteractionData().user;
if (user?.id) {
let roomId;
if (room?.id) {
roomId = room.id;
await storeInteractionRoomData(this.persistence, user.id, roomId);
} else {
roomId = (
await getInteractionRoomData(
this.read.getPersistenceReader(),
user.id
)
).roomId;
}
let githubSearchStorage = new GithubSearchResultStorage(this.persistence,this.read.getPersistenceReader());
await githubSearchStorage.deleteSearchResults(roomId,user);
}
break;
}
case ModalsEnum.ISSUE_LIST_VIEW: {
const room = context.getInteractionData().room;
const user = context.getInteractionData().user;
if (user?.id) {
let roomId;
if (room?.id) {
roomId = room.id;
await storeInteractionRoomData(this.persistence, user.id, roomId);
} else {
roomId = (
await getInteractionRoomData(
this.read.getPersistenceReader(),
user.id
)
).roomId;
}
let githubIssuesStorage = new GithubRepoIssuesStorage(this.persistence,this.read.getPersistenceReader());
await githubIssuesStorage.deleteIssueData(roomId,user);
}
break;
}
}
return { success: true } as any;
}
}