Refactoring: merge video-watch scope into common.
In order to be able to use lit in videowatch related code, we have to merge these scopes.
This commit is contained in:
@ -2,10 +2,43 @@
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { SettingEntries } from '@peertube/peertube-types'
|
||||
import type { RegisterClientOptions } from '@peertube/peertube-types/client/types'
|
||||
import { logger as loggerFunction } from '../../../utils/logger'
|
||||
|
||||
export interface PtContext {
|
||||
ptOptions: RegisterClientOptions
|
||||
// We precise some of the settings in SettingsEntries, to faciliate some type checking.
|
||||
export type LiveChatSettings = SettingEntries & {
|
||||
'chat-per-live-video': boolean
|
||||
'chat-all-lives': boolean
|
||||
'chat-all-non-lives': boolean
|
||||
'chat-videos-list': string
|
||||
'federation-no-remote-chat': boolean
|
||||
'chat-style': string | undefined
|
||||
}
|
||||
|
||||
export class PtContext {
|
||||
public readonly ptOptions: RegisterClientOptions
|
||||
public readonly logger: typeof loggerFunction
|
||||
private _settings: LiveChatSettings | undefined
|
||||
|
||||
constructor (
|
||||
ptOptions: RegisterClientOptions,
|
||||
logger: typeof loggerFunction
|
||||
) {
|
||||
this.ptOptions = ptOptions
|
||||
this.logger = logger
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the livechat settings.
|
||||
* Keep them in cache after first request.
|
||||
*/
|
||||
public async getSettings (): Promise<LiveChatSettings> {
|
||||
if (!this._settings) {
|
||||
this._settings = await this.ptOptions.peertubeHelpers.getSettings() as LiveChatSettings
|
||||
}
|
||||
return this._settings
|
||||
}
|
||||
}
|
||||
|
||||
let context: PtContext
|
||||
@ -18,7 +51,8 @@ export function getPtContext (): PtContext {
|
||||
}
|
||||
|
||||
export function initPtContext (ptOptions: RegisterClientOptions): void {
|
||||
context = {
|
||||
ptOptions
|
||||
}
|
||||
context = new PtContext(
|
||||
ptOptions,
|
||||
loggerFunction
|
||||
)
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
import { html } from 'lit'
|
||||
import { customElement, property, state } from 'lit/decorators.js'
|
||||
import { unsafeHTML } from 'lit/directives/unsafe-html.js'
|
||||
import { helpButtonSVG } from '../../../videowatch/buttons'
|
||||
import { helpButtonSVG } from '../../videowatch/buttons'
|
||||
import { Task } from '@lit/task'
|
||||
import { localizedHelpUrl } from '../../../utils/help'
|
||||
import { ptTr } from '../directives/translation'
|
||||
|
Reference in New Issue
Block a user