2021-05-01 16:30:21 +00:00
|
|
|
import { parseConfigUUIDs } from './config'
|
|
|
|
|
2023-04-21 14:56:48 +00:00
|
|
|
interface VideoHasWebchatSettings {
|
2021-06-08 16:08:58 +00:00
|
|
|
'chat-per-live-video': boolean
|
2021-05-01 16:30:21 +00:00
|
|
|
'chat-all-lives': boolean
|
|
|
|
'chat-all-non-lives': boolean
|
|
|
|
'chat-videos-list': string
|
|
|
|
}
|
|
|
|
|
|
|
|
interface SharedVideoBase {
|
|
|
|
uuid: string
|
|
|
|
isLive: boolean
|
2021-06-08 16:08:58 +00:00
|
|
|
pluginData?: {
|
|
|
|
'livechat-active'?: boolean
|
2023-04-21 14:56:48 +00:00
|
|
|
'livechat-remote'?: boolean
|
2021-06-08 16:08:58 +00:00
|
|
|
}
|
2021-05-01 16:30:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface SharedVideoFrontend extends SharedVideoBase {
|
|
|
|
isLocal: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
interface SharedVideoBackend extends SharedVideoBase {
|
|
|
|
remote: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
type SharedVideo = SharedVideoBackend | SharedVideoFrontend
|
|
|
|
|
2023-04-21 14:56:48 +00:00
|
|
|
/**
|
|
|
|
* Indicate if the video has a local chat.
|
|
|
|
* @param settings plugin settings
|
|
|
|
* @param video the video
|
|
|
|
* @returns true if the video has a local chat
|
|
|
|
*/
|
|
|
|
function videoHasWebchat (settings: VideoHasWebchatSettings, video: SharedVideo): boolean {
|
2021-08-05 16:45:06 +00:00
|
|
|
// Never use webchat on remote videos.
|
|
|
|
if ('isLocal' in video) {
|
|
|
|
if (!video.isLocal) return false
|
|
|
|
} else {
|
|
|
|
if (video.remote) return false
|
2021-05-01 16:30:21 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 16:08:58 +00:00
|
|
|
if (settings['chat-per-live-video'] && video.isLive && video.pluginData && video.pluginData['livechat-active']) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-05-01 16:30:21 +00:00
|
|
|
if (settings['chat-all-lives']) {
|
|
|
|
if (video.isLive) return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings['chat-all-non-lives']) {
|
|
|
|
if (!video.isLive) return true
|
|
|
|
}
|
|
|
|
|
|
|
|
const uuids = parseConfigUUIDs(settings['chat-videos-list'])
|
|
|
|
if (uuids.includes(video.uuid)) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-04-21 14:56:48 +00:00
|
|
|
interface VideoHasRemoteWebchatSettings {
|
|
|
|
'federation-no-remote-chat': boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates if the video has a remote chat.
|
|
|
|
* @param settings plugin settings
|
|
|
|
* @param video the video
|
|
|
|
* @returns true if the video has a remote chat
|
|
|
|
*/
|
|
|
|
function videoHasRemoteWebchat (settings: VideoHasRemoteWebchatSettings, video: SharedVideo): boolean {
|
|
|
|
if (settings['federation-no-remote-chat']) { return false }
|
|
|
|
if ('isLocal' in video) {
|
|
|
|
if (video.isLocal) return false
|
|
|
|
} else {
|
|
|
|
if (!video.remote) return false
|
|
|
|
}
|
|
|
|
if (!video.pluginData) { return false }
|
|
|
|
if (!video.pluginData['livechat-remote']) { return false }
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-05-01 16:30:21 +00:00
|
|
|
export {
|
2023-04-21 14:56:48 +00:00
|
|
|
videoHasWebchat,
|
|
|
|
videoHasRemoteWebchat
|
2021-05-01 16:30:21 +00:00
|
|
|
}
|