-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathUserProfileModal.ts
More file actions
116 lines (98 loc) · 3.56 KB
/
UserProfileModal.ts
File metadata and controls
116 lines (98 loc) · 3.56 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { IHttp, IModify, IPersistence, IRead } from "@rocket.chat/apps-engine/definition/accessors";
import { SlashCommandContext } from "@rocket.chat/apps-engine/definition/slashcommands";
import { ButtonStyle, TextObjectType, UIKitInteractionContext } from "@rocket.chat/apps-engine/definition/uikit";
import { IUIKitModalViewParam } from "@rocket.chat/apps-engine/definition/uikit/UIKitInteractionResponder";
import { AppEnum } from "../enum/App";
import { ModalsEnum } from "../enum/Modals";
import { getBasicUserInfo } from "../helpers/githubSDK";
import { getInteractionRoomData, storeInteractionRoomData } from "../persistance/roomInteraction";
import {} from "@rocket.chat/apps-engine/definition/uikit/"
import { githubActivityGraphUrl } from "../helpers/githubActivityGraphURL";
export async function userProfileModal({
access_token,
modify,
read,
persistence,
http,
slashcommandcontext,
uikitcontext
} : {
access_token: String,
modify : IModify,
read: IRead,
persistence: IPersistence,
http: IHttp,
slashcommandcontext: SlashCommandContext,
uikitcontext?: UIKitInteractionContext
}) : Promise<IUIKitModalViewParam> {
const viewId = ModalsEnum.USER_PROFILE_VIEW;
const block = modify.getCreator().getBlockBuilder();
const room = slashcommandcontext?.getRoom() || uikitcontext?.getInteractionData().room;
const user = slashcommandcontext?.getSender() || uikitcontext?.getInteractionData().user;
if (user?.id){
let roomId;
if (room?.id){
roomId = room.id;
await storeInteractionRoomData(persistence, user.id, roomId);
}
else {
roomId = (await getInteractionRoomData(read.getPersistenceReader(), user.id)).roomId;
}
}
const userInfo = await getBasicUserInfo(http, access_token);
block.addContextBlock({
elements: [
block.newPlainTextObject(userInfo.email, true),
]
})
block.addSectionBlock({
text: block.newPlainTextObject(userInfo.bio),
accessory : block.newImageElement({
imageUrl: userInfo.avatar,
altText: userInfo.name
})
})
block.addContextBlock({
elements: [
block.newPlainTextObject(`followers: ${userInfo.followers}`),
block.newPlainTextObject(`following: ${userInfo.following}`)
]
});
block.addDividerBlock();
block.addImageBlock({imageUrl : githubActivityGraphUrl(userInfo.username), altText: "Github Contribution Graph"});
block.addDividerBlock();
block.addSectionBlock({
text: block.newPlainTextObject("Select from the following options.")
})
block.addActionsBlock({
elements : [
block.newButtonElement({
text : {
text : "Share Profile",
type : TextObjectType.PLAINTEXT
},
actionId: ModalsEnum.SHARE_PROFILE,
style : ButtonStyle.PRIMARY
}),
block.newButtonElement(
{
actionId: ModalsEnum.TRIGGER_ISSUES_CONTEXTUAL_BAR,
value: "Trigger Issues Modal",
text: {
type: TextObjectType.PLAINTEXT,
text: "Issues"
},
style: ButtonStyle.PRIMARY
},
)
]
})
return {
id: viewId,
title: {
type: TextObjectType.PLAINTEXT,
text: userInfo.name
},
blocks: block.getBlocks(),
}
}