-
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathchat-actions.ts
More file actions
49 lines (46 loc) · 1.28 KB
/
chat-actions.ts
File metadata and controls
49 lines (46 loc) · 1.28 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
import { writable } from 'svelte/store';
import { ChatReportUserOptions, ChatUserActions, ChatPollActions } from './chat-constants';
import { reportDialog } from './storage';
export function useBanHammer(
message: Ytc.ParsedMessage,
action: ChatUserActions,
port: Chat.Port | null
): void {
if (action === ChatUserActions.BLOCK) {
port?.postMessage({
type: 'executeChatAction',
message,
action
});
} else if (action === ChatUserActions.REPORT_USER) {
const store = writable(null as null | ChatReportUserOptions);
reportDialog.set({
callback: (selection) => {
port?.postMessage({
type: 'executeChatAction',
message,
action,
reportOption: selection
});
},
optionStore: store
});
}
}
/**
* Ends a poll that is currently active in the live chat
* @param poll The ParsedPoll object containing information about the poll to end
* @param port The port to communicate with the background script
*/
export function endPoll(
poll: Ytc.ParsedPoll,
port: Chat.Port | null
): void {
if (!port) return;
// Use a dedicated executePollAction message type for poll operations
port?.postMessage({
type: 'executePollAction',
poll,
action: ChatPollActions.END_POLL
});
}