peertube-plugin-livechat/shared/lib/video.ts
John Livingston 0e14ec6649
Removed the settings «Chats are only available for local videos».
From now on, webchat can only be activated for local videos.
It will never be displayed on remote videos.
This is because an incompatibility with a new feature (webchat per channel).
Moreover this feature was very limited: the webchat was not shared with the remote instance (this will probably be achieved in a future release).
2021-08-05 18:45:06 +02:00

59 lines
1.2 KiB
TypeScript

import { parseConfigUUIDs } from './config'
interface SharedSettings {
'chat-per-live-video': boolean
'chat-all-lives': boolean
'chat-all-non-lives': boolean
'chat-videos-list': string
}
interface SharedVideoBase {
uuid: string
isLive: boolean
pluginData?: {
'livechat-active'?: boolean
}
}
interface SharedVideoFrontend extends SharedVideoBase {
isLocal: boolean
}
interface SharedVideoBackend extends SharedVideoBase {
remote: boolean
}
type SharedVideo = SharedVideoBackend | SharedVideoFrontend
function videoHasWebchat (settings: SharedSettings, video: SharedVideo): boolean {
// Never use webchat on remote videos.
if ('isLocal' in video) {
if (!video.isLocal) return false
} else {
if (video.remote) return false
}
if (settings['chat-per-live-video'] && video.isLive && video.pluginData && video.pluginData['livechat-active']) {
return true
}
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
}
export {
videoHasWebchat
}