eslint 8.57 WIP:

* tweaking rules
* fixing issues
This commit is contained in:
John Livingston 2024-09-09 18:47:21 +02:00
parent 7b3d93b290
commit c010758164
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
42 changed files with 361 additions and 178 deletions

View File

@ -14,7 +14,7 @@ module.exports = {
// extending the kebab-case to accept ConverseJS class names. // extending the kebab-case to accept ConverseJS class names.
'^([a-z][a-z0-9]*)(-[a-z0-9]+)*((__|--)[a-z]+(-[a-z0-9]+)*)?$', '^([a-z][a-z0-9]*)(-[a-z0-9]+)*((__|--)[a-z]+(-[a-z0-9]+)*)?$',
{ {
message: 'Expected class selector to be kebab-case, or ConverseJS-style.', message: 'Expected class selector to be kebab-case, or ConverseJS-style.'
} }
] ]
} }

View File

@ -243,7 +243,10 @@ function register (clientOptions: RegisterClientOptions): void {
} }
} catch (error: any) { } catch (error: any) {
console.error(error) console.error(error)
peertubeHelpers.notifier.error(error.toString(), await peertubeHelpers.translate(LOC_LOADING_ERROR)) peertubeHelpers.notifier.error(
(error as Error).toString(),
await peertubeHelpers.translate(LOC_LOADING_ERROR)
)
} }
} }
}) })

View File

@ -46,7 +46,7 @@ async function register (clientOptions: RegisterClientOptions): Promise<void> {
]) ])
const webchatFieldOptions: RegisterClientFormFieldOptions = { const webchatFieldOptions: RegisterClientFormFieldOptions = {
name: 'livechat-active', name: 'livechat-active',
label: label, label,
descriptionHTML: description, descriptionHTML: description,
type: 'input-checkbox', type: 'input-checkbox',
default: true, default: true,

View File

@ -22,7 +22,7 @@ export class AdminFirewallElement extends LivechatElement {
public validationError?: ValidationError public validationError?: ValidationError
@state() @state()
public actionDisabled: boolean = false public actionDisabled = false
private _asyncTaskRender: Task private _asyncTaskRender: Task
@ -101,7 +101,7 @@ export class AdminFirewallElement extends LivechatElement {
}) })
} }
public readonly getInputValidationClass = (propertyName: string): { [key: string]: boolean } => { public readonly getInputValidationClass = (propertyName: string): Record<string, boolean> => {
const validationErrorTypes: ValidationErrorType[] | undefined = const validationErrorTypes: ValidationErrorType[] | undefined =
this.validationError?.properties[`${propertyName}`] this.validationError?.properties[`${propertyName}`]
return validationErrorTypes ? (validationErrorTypes.length ? { 'is-invalid': true } : { 'is-valid': true }) : {} return validationErrorTypes ? (validationErrorTypes.length ? { 'is-invalid': true } : { 'is-valid': true }) : {}

View File

@ -2,6 +2,9 @@
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
// FIXME: @stylistic/indent is buggy with strings literrals.
/* eslint-disable @stylistic/indent */
import type { AdminFirewallElement } from '../elements/admin-firewall' import type { AdminFirewallElement } from '../elements/admin-firewall'
import type { TemplateResult } from 'lit' import type { TemplateResult } from 'lit'
import type { DynamicFormHeader, DynamicFormSchema } from '../../../lib/elements/dynamic-table-form' import type { DynamicFormHeader, DynamicFormSchema } from '../../../lib/elements/dynamic-table-form'

View File

@ -32,7 +32,7 @@ export class ChannelConfigurationElement extends LivechatElement {
public validationError?: ValidationError public validationError?: ValidationError
@state() @state()
public actionDisabled: boolean = false public actionDisabled = false
private _asyncTaskRender: Task private _asyncTaskRender: Task
@ -113,7 +113,7 @@ export class ChannelConfigurationElement extends LivechatElement {
} }
} }
public readonly getInputValidationClass = (propertyName: string): { [key: string]: boolean } => { public readonly getInputValidationClass = (propertyName: string): Record<string, boolean> => {
const validationErrorTypes: ValidationErrorType[] | undefined = const validationErrorTypes: ValidationErrorType[] | undefined =
this.validationError?.properties[`${propertyName}`] this.validationError?.properties[`${propertyName}`]
return validationErrorTypes ? (validationErrorTypes.length ? { 'is-invalid': true } : { 'is-valid': true }) : {} return validationErrorTypes ? (validationErrorTypes.length ? { 'is-invalid': true } : { 'is-valid': true }) : {}

View File

@ -30,7 +30,7 @@ export class ChannelEmojisElement extends LivechatElement {
public validationError?: ValidationError public validationError?: ValidationError
@state() @state()
public actionDisabled: boolean = false public actionDisabled = false
private _asyncTaskRender: Task private _asyncTaskRender: Task
@ -192,7 +192,7 @@ export class ChannelEmojisElement extends LivechatElement {
throw new Error('Invalid data') throw new Error('Invalid data')
} }
const url = await this._convertImageToDataUrl(entry.url) const url = await this._convertImageToDataUrl(entry.url as string)
const sn = entry.sn as string const sn = entry.sn as string
const item: ChannelEmojisConfiguration['emojis']['customEmojis'][0] = { const item: ChannelEmojisConfiguration['emojis']['customEmojis'][0] = {
@ -211,7 +211,7 @@ export class ChannelEmojisElement extends LivechatElement {
await this.ptTranslate(LOC_ACTION_IMPORT_EMOJIS_INFO) await this.ptTranslate(LOC_ACTION_IMPORT_EMOJIS_INFO)
) )
} catch (err: any) { } catch (err: any) {
this.ptNotifier.error(err.toString(), await this.ptTranslate(LOC_ERROR)) this.ptNotifier.error((err as Error).toString(), await this.ptTranslate(LOC_ERROR))
} finally { } finally {
this.actionDisabled = false this.actionDisabled = false
} }
@ -250,7 +250,7 @@ export class ChannelEmojisElement extends LivechatElement {
a.remove() a.remove()
} catch (err: any) { } catch (err: any) {
this.logger.error(err) this.logger.error(err)
this.ptNotifier.error(err.toString()) this.ptNotifier.error((err as Error).toString())
} finally { } finally {
this.actionDisabled = false this.actionDisabled = false
} }

View File

@ -2,6 +2,9 @@
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
// FIXME: @stylistic/indent is buggy with strings literrals.
/* eslint-disable @stylistic/indent */
import { html } from 'lit' import { html } from 'lit'
import { customElement, state } from 'lit/decorators.js' import { customElement, state } from 'lit/decorators.js'
import { ptTr } from '../../lib/directives/translation' import { ptTr } from '../../lib/directives/translation'

View File

@ -2,6 +2,9 @@
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
// FIXME: @stylistic/indent is buggy with strings literrals.
/* eslint-disable @stylistic/indent */
import { LivechatElement } from '../../lib/elements/livechat' import { LivechatElement } from '../../lib/elements/livechat'
import { ptTr } from '../../lib/directives/translation' import { ptTr } from '../../lib/directives/translation'
import { html, TemplateResult } from 'lit' import { html, TemplateResult } from 'lit'

View File

@ -2,6 +2,9 @@
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
// FIXME: @stylistic/indent is buggy with strings literrals.
/* eslint-disable @stylistic/indent */
import type { ChannelConfigurationElement } from '../channel-configuration' import type { ChannelConfigurationElement } from '../channel-configuration'
import type { DynamicFormHeader, DynamicFormSchema } from '../../../lib/elements/dynamic-table-form' import type { DynamicFormHeader, DynamicFormSchema } from '../../../lib/elements/dynamic-table-form'
import { ptTr } from '../../../lib/directives/translation' import { ptTr } from '../../../lib/directives/translation'
@ -9,7 +12,7 @@ import { html, TemplateResult } from 'lit'
import { classMap } from 'lit/directives/class-map.js' import { classMap } from 'lit/directives/class-map.js'
export function tplChannelConfiguration (el: ChannelConfigurationElement): TemplateResult { export function tplChannelConfiguration (el: ChannelConfigurationElement): TemplateResult {
const tableHeaderList: {[key: string]: DynamicFormHeader} = { const tableHeaderList: Record<string, DynamicFormHeader> = {
forbiddenWords: { forbiddenWords: {
entries: { entries: {
colName: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_LABEL), colName: ptTr(LOC_LIVECHAT_CONFIGURATION_CHANNEL_FORBIDDEN_WORDS_LABEL),
@ -57,7 +60,7 @@ export function tplChannelConfiguration (el: ChannelConfigurationElement): Templ
} }
} }
} }
const tableSchema: {[key: string]: DynamicFormSchema} = { const tableSchema: Record<string, DynamicFormSchema> = {
forbiddenWords: { forbiddenWords: {
entries: { entries: {
inputType: 'tags', inputType: 'tags',

View File

@ -2,6 +2,9 @@
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
// FIXME: @stylistic/indent is buggy with strings literrals.
/* eslint-disable @stylistic/indent */
import type { ChannelEmojisElement } from '../channel-emojis' import type { ChannelEmojisElement } from '../channel-emojis'
import type { DynamicFormHeader, DynamicFormSchema } from '../../../lib/elements/dynamic-table-form' import type { DynamicFormHeader, DynamicFormSchema } from '../../../lib/elements/dynamic-table-form'
import { maxEmojisPerChannel } from 'shared/lib/emojis' import { maxEmojisPerChannel } from 'shared/lib/emojis'

View File

@ -162,7 +162,8 @@ export class ChannelDetailsService {
} }
for (const channel of channels.data) { for (const channel of channels.data) {
channel.livechatConfigurationUri = '/p/livechat/configuration/channel?channelId=' + encodeURIComponent(channel.id) channel.livechatConfigurationUri =
'/p/livechat/configuration/channel?channelId=' + encodeURIComponent(channel.id as string | number)
// Note: since Peertube v6.0.0, channel.avatar is dropped, and we have to use channel.avatars. // Note: since Peertube v6.0.0, channel.avatar is dropped, and we have to use channel.avatars.
// So, if !channel.avatar, we will search a suitable one in channel.avatars, and fill channel.avatar. // So, if !channel.avatar, we will search a suitable one in channel.avatars, and fill channel.avatar.
@ -196,10 +197,11 @@ export class ChannelDetailsService {
} }
public async fetchEmojisConfiguration (channelId: number): Promise<ChannelEmojisConfiguration> { public async fetchEmojisConfiguration (channelId: number): Promise<ChannelEmojisConfiguration> {
const url = getBaseRoute(this._registerClientOptions) +
'/api/configuration/channel/emojis/' +
encodeURIComponent(channelId)
const response = await fetch( const response = await fetch(
getBaseRoute(this._registerClientOptions) + url,
'/api/configuration/channel/emojis/' +
encodeURIComponent(channelId),
{ {
method: 'GET', method: 'GET',
headers: this._headers headers: this._headers
@ -311,10 +313,11 @@ export class ChannelDetailsService {
channelId: number, channelId: number,
channelEmojis: ChannelEmojis channelEmojis: ChannelEmojis
): Promise<ChannelEmojisConfiguration> { ): Promise<ChannelEmojisConfiguration> {
const url = getBaseRoute(this._registerClientOptions) +
'/api/configuration/channel/emojis/' +
encodeURIComponent(channelId)
const response = await fetch( const response = await fetch(
getBaseRoute(this._registerClientOptions) + url,
'/api/configuration/channel/emojis/' +
encodeURIComponent(channelId),
{ {
method: 'POST', method: 'POST',
headers: this._headers, headers: this._headers,
@ -330,11 +333,12 @@ export class ChannelDetailsService {
} }
public async enableEmojisOnlyModeOnAllRooms (channelId: number): Promise<void> { public async enableEmojisOnlyModeOnAllRooms (channelId: number): Promise<void> {
const url = getBaseRoute(this._registerClientOptions) +
'/api/configuration/channel/emojis/' +
encodeURIComponent(channelId) +
'/enable_emoji_only'
const response = await fetch( const response = await fetch(
getBaseRoute(this._registerClientOptions) + url,
'/api/configuration/channel/emojis/' +
encodeURIComponent(channelId) +
'/enable_emoji_only',
{ {
method: 'POST', method: 'POST',
headers: this._headers headers: this._headers

View File

@ -4,7 +4,7 @@
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
// This content comes from the file assets/images/plus-square.svg, from the Feather icons set https://feathericons.com/ // This content comes from the file assets/images/plus-square.svg, from the Feather icons set https://feathericons.com/
export const AddSVG: string = export const AddSVG =
`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
aria-hidden="true" aria-hidden="true"
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
@ -14,7 +14,7 @@ export const AddSVG: string =
</svg>` </svg>`
// This content comes from the file assets/images/x-square.svg, from the Feather icons set https://feathericons.com/ // This content comes from the file assets/images/x-square.svg, from the Feather icons set https://feathericons.com/
export const RemoveSVG: string = export const RemoveSVG =
`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
aria-hidden="true" aria-hidden="true"
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"

View File

@ -13,8 +13,8 @@ import { getPtContext } from '../contexts/peertube'
export class TranslationDirective extends AsyncDirective { export class TranslationDirective extends AsyncDirective {
private readonly _peertubeHelpers: RegisterClientHelpers private readonly _peertubeHelpers: RegisterClientHelpers
private _translatedValue: string = '' private _translatedValue = ''
private _localizationId: string = '' private _localizationId = ''
private _allowUnsafeHTML = false private _allowUnsafeHTML = false
@ -25,7 +25,7 @@ export class TranslationDirective extends AsyncDirective {
this._asyncUpdateTranslation().then(() => {}, () => {}) this._asyncUpdateTranslation().then(() => {}, () => {})
} }
public override render = (locId: string, allowHTML: boolean = false): TemplateResult | string => { public override render = (locId: string, allowHTML = false): TemplateResult | string => {
this._localizationId = locId // TODO Check current component for context (to infer the prefix) this._localizationId = locId // TODO Check current component for context (to infer the prefix)
this._allowUnsafeHTML = allowHTML this._allowUnsafeHTML = allowHTML

View File

@ -3,6 +3,9 @@
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
// FIXME: @stylistic/indent is buggy with strings literrals.
/* eslint-disable @stylistic/indent */
import { ptTr } from '../directives/translation' import { ptTr } from '../directives/translation'
import { html } from 'lit' import { html } from 'lit'
import { customElement, property } from 'lit/decorators.js' import { customElement, property } from 'lit/decorators.js'

View File

@ -3,6 +3,9 @@
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
// FIXME: @stylistic/indent is buggy with strings literrals.
/* eslint-disable @stylistic/indent */
import type { TagsInputElement } from './tags-input' import type { TagsInputElement } from './tags-input'
import type { DirectiveResult } from 'lit/directive' import type { DirectiveResult } from 'lit/directive'
import { ValidationErrorType } from '../models/validation' import { ValidationErrorType } from '../models/validation'
@ -20,26 +23,26 @@ import { AddSVG, RemoveSVG } from '../buttons'
type DynamicTableAcceptedTypes = number | string | boolean | Date | Array<number | string> type DynamicTableAcceptedTypes = number | string | boolean | Date | Array<number | string>
type DynamicTableAcceptedInputTypes = 'textarea' type DynamicTableAcceptedInputTypes = 'textarea'
| 'select' | 'select'
| 'checkbox' | 'checkbox'
| 'range' | 'range'
| 'color' | 'color'
| 'date' | 'date'
| 'datetime' | 'datetime'
| 'datetime-local' | 'datetime-local'
| 'email' | 'email'
| 'file' | 'file'
| 'image' | 'image'
| 'month' | 'month'
| 'number' | 'number'
| 'password' | 'password'
| 'tel' | 'tel'
| 'text' | 'text'
| 'time' | 'time'
| 'url' | 'url'
| 'week' | 'week'
| 'tags' | 'tags'
| 'image-file' | 'image-file'
interface CellDataSchema { interface CellDataSchema {
min?: number min?: number
@ -47,7 +50,7 @@ interface CellDataSchema {
minlength?: number minlength?: number
maxlength?: number maxlength?: number
size?: number size?: number
options?: { [key: string]: string } options?: Record<string, string>
datalist?: DynamicTableAcceptedTypes[] datalist?: DynamicTableAcceptedTypes[]
separator?: string separator?: string
inputType?: DynamicTableAcceptedInputTypes inputType?: DynamicTableAcceptedInputTypes
@ -59,7 +62,7 @@ interface CellDataSchema {
interface DynamicTableRowData { interface DynamicTableRowData {
_id: number _id: number
_originalIndex: number _originalIndex: number
row: { [key: string]: DynamicTableAcceptedTypes } row: Record<string, DynamicTableAcceptedTypes>
} }
interface DynamicFormHeaderCellData { interface DynamicFormHeaderCellData {
@ -68,10 +71,8 @@ interface DynamicFormHeaderCellData {
headerClassList?: string[] headerClassList?: string[]
} }
export interface DynamicFormHeader { export type DynamicFormHeader = Record<string, DynamicFormHeaderCellData>
[key: string]: DynamicFormHeaderCellData export type DynamicFormSchema = Record<string, CellDataSchema>
}
export interface DynamicFormSchema { [key: string]: CellDataSchema }
@customElement('livechat-dynamic-table-form') @customElement('livechat-dynamic-table-form')
export class DynamicTableFormElement extends LivechatElement { export class DynamicTableFormElement extends LivechatElement {
@ -85,19 +86,19 @@ export class DynamicTableFormElement extends LivechatElement {
public maxLines?: number = undefined public maxLines?: number = undefined
@property() @property()
public validation?: {[key: string]: ValidationErrorType[] } public validation?: Record<string, ValidationErrorType[]>
@property({ attribute: false }) @property({ attribute: false })
public validationPrefix: string = '' public validationPrefix = ''
@property({ attribute: false }) @property({ attribute: false })
public rows: Array<{ [key: string]: DynamicTableAcceptedTypes }> = [] public rows: Array<Record<string, DynamicTableAcceptedTypes>> = []
@state() @state()
public _rowsById: DynamicTableRowData[] = [] public _rowsById: DynamicTableRowData[] = []
@property({ attribute: false }) @property({ attribute: false })
public formName: string = '' public formName = ''
@state() @state()
private _lastRowId = 1 private _lastRowId = 1
@ -112,7 +113,7 @@ export class DynamicTableFormElement extends LivechatElement {
} }
} }
private readonly _getDefaultRow = (): { [key: string]: DynamicTableAcceptedTypes } => { private readonly _getDefaultRow = (): Record<string, DynamicTableAcceptedTypes> => {
this._updateLastRowId() this._updateLastRowId()
return Object.fromEntries([...Object.entries(this.schema).map((entry) => [entry[0], entry[1].default ?? ''])]) return Object.fromEntries([...Object.entries(this.schema).map((entry) => [entry[0], entry[1].default ?? ''])])
} }
@ -245,11 +246,11 @@ export class DynamicTableFormElement extends LivechatElement {
return html`<tr id=${inputId}> return html`<tr id=${inputId}>
${Object.keys(this.header) ${Object.keys(this.header)
.sort((k1, k2) => this.columnOrder.indexOf(k1) - this.columnOrder.indexOf(k2)) .sort((k1, k2) => this.columnOrder.indexOf(k1) - this.columnOrder.indexOf(k2))
.map(key => this.renderDataCell(key, .map(key => this.renderDataCell(key,
rowData.row[key] ?? this.schema[key].default, rowData.row[key] ?? this.schema[key].default,
rowData._id, rowData._id,
rowData._originalIndex))} rowData._originalIndex))}
<td class="form-group"> <td class="form-group">
<button type="button" <button type="button"
class="dynamic-table-remove-row" class="dynamic-table-remove-row"
@ -457,8 +458,7 @@ export class DynamicTableFormElement extends LivechatElement {
inputTitle, inputTitle,
propertyName, propertyName,
propertySchema, propertySchema,
(propertyValue)?.join(propertySchema.separator ?? ',') ?? (propertyValue)?.join(propertySchema.separator ?? ',') ?? propertyValue ?? propertySchema.default ?? '',
propertyValue ?? propertySchema.default ?? '',
originalIndex)} originalIndex)}
${feedback} ${feedback}
` `
@ -473,8 +473,7 @@ export class DynamicTableFormElement extends LivechatElement {
inputTitle, inputTitle,
propertyName, propertyName,
propertySchema, propertySchema,
(propertyValue)?.join(propertySchema.separator ?? ',') ?? (propertyValue)?.join(propertySchema.separator ?? ',') ?? propertyValue ?? propertySchema.default ?? '',
propertyValue ?? propertySchema.default ?? '',
originalIndex)} originalIndex)}
${feedback} ${feedback}
` `
@ -498,8 +497,10 @@ export class DynamicTableFormElement extends LivechatElement {
} }
if (!formElement) { if (!formElement) {
this.logger.warn(`value type '${(propertyValue.constructor.toString())}' is incompatible` + this.logger.warn(
`with field type '${propertySchema.inputType as string}' for form entry '${propertyName.toString()}'.`) `value type '${(propertyValue.constructor.toString())}' is incompatible` +
`with field type '${propertySchema.inputType as string}' for form entry '${propertyName.toString()}'.`
)
} }
const classList = ['form-group'] const classList = ['form-group']
@ -678,7 +679,7 @@ export class DynamicTableFormElement extends LivechatElement {
} }
_getInputValidationClass = (propertyName: string, _getInputValidationClass = (propertyName: string,
originalIndex: number): { [key: string]: boolean } => { originalIndex: number): Record<string, boolean> => {
const validationErrorTypes: ValidationErrorType[] | undefined = const validationErrorTypes: ValidationErrorType[] | undefined =
this.validation?.[`${this.validationPrefix}.${originalIndex}.${propertyName}`] this.validation?.[`${this.validationPrefix}.${originalIndex}.${propertyName}`]

View File

@ -18,7 +18,7 @@ export class HelpButtonElement extends LivechatElement {
public buttonTitle: string | DirectiveResult = ptTr(LOC_ONLINE_HELP) public buttonTitle: string | DirectiveResult = ptTr(LOC_ONLINE_HELP)
@property({ attribute: false }) @property({ attribute: false })
public page: string = '' public page = ''
@state() @state()
public url: URL = new URL('https://lmddgtfy.net/') public url: URL = new URL('https://lmddgtfy.net/')

View File

@ -1,6 +1,10 @@
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/> // SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
// FIXME: @stylistic/indent is buggy with strings literrals.
/* eslint-disable @stylistic/indent */
import { LivechatElement } from './livechat' import { LivechatElement } from './livechat'
import { html } from 'lit' import { html } from 'lit'
import type { DirectiveResult } from 'lit/directive' import type { DirectiveResult } from 'lit/directive'

View File

@ -3,6 +3,9 @@
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
// FIXME: @stylistic/indent is buggy with strings literrals.
/* eslint-disable @stylistic/indent */
import { LivechatElement } from './livechat' import { LivechatElement } from './livechat'
import { ptTr } from '../directives/translation' import { ptTr } from '../directives/translation'
import { html } from 'lit' import { html } from 'lit'
@ -21,10 +24,11 @@ import type { DirectiveResult } from 'lit/directive'
// Then replace the main color by «currentColor» // Then replace the main color by «currentColor»
const copySVG = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 4.233 4.233"> const copySVG = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 4.233 4.233">
<g style="stroke-width:1.00021;stroke-miterlimit:4;stroke-dasharray:none">` + <g style="stroke-width:1.00021;stroke-miterlimit:4;stroke-dasharray:none">` +
// eslint-disable-next-line max-len // eslint-disable-next-line max-len, @stylistic/indent-binary-ops
'<path style="opacity:.998;fill:none;fill-opacity:1;stroke:currentColor;stroke-width:1.17052;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" d="m4.084 4.046-.616.015-.645-.004a.942.942 0 0 1-.942-.942v-4.398a.94.94 0 0 1 .942-.943H7.22a.94.94 0 0 1 .942.943l-.006.334-.08.962" transform="matrix(.45208 0 0 .45208 -.528 1.295)"/>' + '<path style="opacity:.998;fill:none;fill-opacity:1;stroke:currentColor;stroke-width:1.17052;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" d="m4.084 4.046-.616.015-.645-.004a.942.942 0 0 1-.942-.942v-4.398a.94.94 0 0 1 .942-.943H7.22a.94.94 0 0 1 .942.943l-.006.334-.08.962" transform="matrix(.45208 0 0 .45208 -.528 1.295)"/>' +
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
'<path style="opacity:.998;fill:none;fill-opacity:1;stroke:currentColor;stroke-width:1.17052;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" d="M8.434 5.85c-.422.009-1.338.009-1.76.01-.733.004-2.199 0-2.199 0a.94.94 0 0 1-.942-.941V.52a.94.94 0 0 1 .942-.942h4.398a.94.94 0 0 1 .943.942s.004 1.466 0 2.2c-.003.418-.019 1.251-.006 1.67.024.812-.382 1.439-1.376 1.46z" transform="matrix(.45208 0 0 .45208 -.528 1.295)"/>' + '<path style="opacity:.998;fill:none;fill-opacity:1;stroke:currentColor;stroke-width:1.17052;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" d="M8.434 5.85c-.422.009-1.338.009-1.76.01-.733.004-2.199 0-2.199 0a.94.94 0 0 1-.942-.941V.52a.94.94 0 0 1 .942-.942h4.398a.94.94 0 0 1 .943.942s.004 1.466 0 2.2c-.003.418-.019 1.251-.006 1.67.024.812-.382 1.439-1.376 1.46z" transform="matrix(.45208 0 0 .45208 -.528 1.295)"/>' +
// eslint-disable-next-line @stylistic/indent-binary-ops
`</g> `</g>
</svg>` </svg>`
@ -64,10 +68,10 @@ export class TagsInputElement extends LivechatElement {
private readonly _isPressingKey: string[] = [] private readonly _isPressingKey: string[] = []
@property({ attribute: false }) @property({ attribute: false })
public separator: string = '\n' public separator = '\n'
@property({ attribute: false }) @property({ attribute: false })
public animDuration: number = 200 public animDuration = 200
/** /**
* Overloading the standard focus method. * Overloading the standard focus method.
@ -245,8 +249,9 @@ export class TagsInputElement extends LivechatElement {
if (!this._isPressingKey.includes(e.key)) { if (!this._isPressingKey.includes(e.key)) {
this._isPressingKey.push(e.key) this._isPressingKey.push(e.key)
if ((target.selectionStart === target.selectionEnd) && if (
target.selectionStart === 0) { (target.selectionStart === target.selectionEnd) && target.selectionStart === 0
) {
this._handleDeleteTag((this._searchedTagsIndex.length) this._handleDeleteTag((this._searchedTagsIndex.length)
? this._searchedTagsIndex.slice(-1)[0] ? this._searchedTagsIndex.slice(-1)[0]
: (this.value.length - 1)) : (this.value.length - 1))
@ -259,8 +264,9 @@ export class TagsInputElement extends LivechatElement {
if (!this._isPressingKey.includes(e.key)) { if (!this._isPressingKey.includes(e.key)) {
this._isPressingKey.push(e.key) this._isPressingKey.push(e.key)
if ((target.selectionStart === target.selectionEnd) && if (
target.selectionStart === target.value.length) { (target.selectionStart === target.selectionEnd) && target.selectionStart === target.value.length
) {
this._handleDeleteTag((this._searchedTagsIndex.length) this._handleDeleteTag((this._searchedTagsIndex.length)
? this._searchedTagsIndex[0] ? this._searchedTagsIndex[0]
: 0) : 0)

View File

@ -2,6 +2,9 @@
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
// FIXME: @stylistic/indent is buggy with strings literrals.
/* eslint-disable @stylistic/indent */
import type { LivechatTokenListElement } from '../token-list' import type { LivechatTokenListElement } from '../token-list'
import { html, TemplateResult } from 'lit' import { html, TemplateResult } from 'lit'
import { unsafeHTML } from 'lit/directives/unsafe-html.js' import { unsafeHTML } from 'lit/directives/unsafe-html.js'
@ -23,11 +26,11 @@ export function tplTokenList (el: LivechatTokenListElement): TemplateResult {
<tbody> <tbody>
${ ${
repeat(el.tokenList ?? [], (token) => token.id, (token) => { repeat(el.tokenList ?? [], (token) => token.id, (token) => {
let dateStr: string = '' let dateStr = ''
try { try {
const date = new Date(token.date) const date = new Date(token.date)
dateStr = date.toLocaleDateString() + ' ' + date.toLocaleTimeString() dateStr = date.toLocaleDateString() + ' ' + date.toLocaleTimeString()
} catch (err) {} } catch (_err) {}
return html`<tr> return html`<tr>
<td>${ <td>${
el.mode === 'select' el.mode === 'select'

View File

@ -27,7 +27,7 @@ export class LivechatTokenListElement extends LivechatElement {
public currentSelectedToken?: LivechatToken public currentSelectedToken?: LivechatToken
@property({ attribute: false }) @property({ attribute: false })
public actionDisabled: boolean = false public actionDisabled = false
private readonly _tokenListService: TokenListService private readonly _tokenListService: TokenListService
private readonly _asyncTaskRender: Task private readonly _asyncTaskRender: Task
@ -83,7 +83,7 @@ export class LivechatTokenListElement extends LivechatElement {
this.dispatchEvent(new CustomEvent('update', {})) this.dispatchEvent(new CustomEvent('update', {}))
} catch (err: any) { } catch (err: any) {
this.logger.error(err) this.logger.error(err)
this.ptNotifier.error(err.toString(), await this.ptTranslate(LOC_ERROR)) this.ptNotifier.error((err as Error).toString(), await this.ptTranslate(LOC_ERROR))
} finally { } finally {
this.actionDisabled = false this.actionDisabled = false
} }
@ -102,7 +102,7 @@ export class LivechatTokenListElement extends LivechatElement {
this.dispatchEvent(new CustomEvent('update', {})) this.dispatchEvent(new CustomEvent('update', {}))
} catch (err: any) { } catch (err: any) {
this.logger.error(err) this.logger.error(err)
this.ptNotifier.error(err.toString(), await this.ptTranslate(LOC_ERROR)) this.ptNotifier.error((err as Error).toString(), await this.ptTranslate(LOC_ERROR))
} finally { } finally {
this.actionDisabled = false this.actionDisabled = false
} }

View File

@ -12,7 +12,7 @@ export enum ValidationErrorType {
} }
export class ValidationError extends Error { export class ValidationError extends Error {
properties: {[key: string]: ValidationErrorType[] } = {} properties: Record<string, ValidationErrorType[]> = {}
constructor (name: string, message: string | undefined, properties: ValidationError['properties']) { constructor (name: string, message: string | undefined, properties: ValidationError['properties']) {
super(message) super(message)

View File

@ -60,8 +60,8 @@ async function initChat (video: Video): Promise<void> {
return return
} }
let showShareUrlButton: boolean = false let showShareUrlButton = false
let showPromote: boolean = false let showPromote = false
if (video.isLocal) { // No need for shareButton on remote chats. if (video.isLocal) { // No need for shareButton on remote chats.
const chatShareUrl = settings['chat-share-url'] ?? '' const chatShareUrl = settings['chat-share-url'] ?? ''
if (chatShareUrl === 'everyone') { if (chatShareUrl === 'everyone') {
@ -187,9 +187,10 @@ async function _insertChatDom (
callback: async () => { callback: async () => {
try { try {
// First we must get the room JID (can be video.uuid@ or channel.id@) // First we must get the room JID (can be video.uuid@ or channel.id@)
const url = getBaseRoute(ptContext.ptOptions) + '/api/configuration/room/' +
encodeURIComponent(video.uuid)
const response = await fetch( const response = await fetch(
getBaseRoute(ptContext.ptOptions) + '/api/configuration/room/' + url,
encodeURIComponent(video.uuid),
{ {
method: 'GET', method: 'GET',
headers: peertubeHelpers.getAuthHeader() headers: peertubeHelpers.getAuthHeader()
@ -303,7 +304,7 @@ async function _openChat (video: Video): Promise<void | false> {
// Loading converseJS... // Loading converseJS...
await displayConverseJS(ptContext.ptOptions, container, roomkey, 'peertube-video', false) await displayConverseJS(ptContext.ptOptions, container, roomkey, 'peertube-video', false)
} catch (err) { } catch (_err) {
// Displaying an error page. // Displaying an error page.
if (container) { if (container) {
const message = document.createElement('div') const message = document.createElement('div')

View File

@ -14,7 +14,7 @@ import { getIframeUri, getXMPPAddr, UriOptions } from '../uri'
import { isAnonymousUser } from '../../../utils/user' import { isAnonymousUser } from '../../../utils/user'
// First is default tab. // First is default tab.
const validTabNames = ['embed', 'dock', 'peertube', 'xmpp'] as const const validTabNames: string[] = ['embed', 'dock', 'peertube', 'xmpp'] as const
type ValidTabNames = typeof validTabNames[number] type ValidTabNames = typeof validTabNames[number]
@ -61,49 +61,49 @@ export class ShareChatElement extends LivechatElement {
* Should we render the XMPP tab? * Should we render the XMPP tab?
*/ */
@property({ attribute: false }) @property({ attribute: false })
public xmppUriEnabled: boolean = false public xmppUriEnabled = false
/** /**
* Should we render the Dock tab? * Should we render the Dock tab?
*/ */
@property({ attribute: false }) @property({ attribute: false })
public dockEnabled: boolean = false public dockEnabled = false
/** /**
* Can we use autocolors? * Can we use autocolors?
*/ */
@property({ attribute: false }) @property({ attribute: false })
public autocolorsAvailable: boolean = false public autocolorsAvailable = false
/** /**
* In the Embed tab, should we generated an iframe link. * In the Embed tab, should we generated an iframe link.
*/ */
@property({ attribute: false }) @property({ attribute: false })
public embedIFrame: boolean = false public embedIFrame = false
/** /**
* In the Embed tab, should we generated a read-only chat link. * In the Embed tab, should we generated a read-only chat link.
*/ */
@property({ attribute: false }) @property({ attribute: false })
public embedReadOnly: boolean = false public embedReadOnly = false
/** /**
* Read-only, with scrollbar? * Read-only, with scrollbar?
*/ */
@property({ attribute: false }) @property({ attribute: false })
public embedReadOnlyScrollbar: boolean = false public embedReadOnlyScrollbar = false
/** /**
* Read-only, transparent background? * Read-only, transparent background?
*/ */
@property({ attribute: false }) @property({ attribute: false })
public embedReadOnlyTransparentBackground: boolean = false public embedReadOnlyTransparentBackground = false
/** /**
* In the Embed tab, should we use current theme color? * In the Embed tab, should we use current theme color?
*/ */
@property({ attribute: false }) @property({ attribute: false })
public embedAutocolors: boolean = false public embedAutocolors = false
protected override firstUpdated (changedProperties: PropertyValues): void { protected override firstUpdated (changedProperties: PropertyValues): void {
super.firstUpdated(changedProperties) super.firstUpdated(changedProperties)
@ -156,7 +156,7 @@ export class ShareChatElement extends LivechatElement {
return return
} }
this.logger.log('Restoring previous state') this.logger.log('Restoring previous state')
if (validTabNames.includes(v.currentTab)) { if (validTabNames.includes(v.currentTab as string)) {
this.currentTab = v.currentTab this.currentTab = v.currentTab
} }
this.embedIFrame = !!v.embedIFrame this.embedIFrame = !!v.embedIFrame

View File

@ -2,6 +2,9 @@
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
// FIXME: @stylistic/indent is buggy with strings literrals.
/* eslint-disable @stylistic/indent */
import type { ShareChatElement } from '../share-chat' import type { ShareChatElement } from '../share-chat'
import { html, TemplateResult } from 'lit' import { html, TemplateResult } from 'lit'
import { ptTr } from '../../../lib/directives/translation' import { ptTr } from '../../../lib/directives/translation'

View File

@ -71,8 +71,7 @@ async function shareChatUrl (
addedNodes.forEach(node => { addedNodes.forEach(node => {
if ((node as HTMLElement).localName === 'ngb-modal-window') { if ((node as HTMLElement).localName === 'ngb-modal-window') {
logger.info('Detecting a new modal, checking if this is the good one...') logger.info('Detecting a new modal, checking if this is the good one...')
if (!(node as HTMLElement).querySelector) { return } const title = (node as HTMLElement).querySelector?.('.modal-title')
const title = (node as HTMLElement).querySelector('.modal-title')
if (!(title?.textContent === labelShare)) { if (!(title?.textContent === labelShare)) {
return return
} }

View File

@ -4,6 +4,7 @@
import type { RegisterClientOptions } from '@peertube/peertube-types/client' import type { RegisterClientOptions } from '@peertube/peertube-types/client'
import type { Video } from '@peertube/peertube-types' import type { Video } from '@peertube/peertube-types'
import type { LiveChatSettings } from '../lib/contexts/peertube'
import { AutoColors, isAutoColorsAvailable } from 'shared/lib/autocolors' import { AutoColors, isAutoColorsAvailable } from 'shared/lib/autocolors'
import { getBaseRoute } from '../../utils/uri' import { getBaseRoute } from '../../utils/uri'
import { logger } from '../../utils/logger' import { logger } from '../../utils/logger'
@ -17,7 +18,7 @@ interface UriOptions {
} }
function getIframeUri ( function getIframeUri (
registerOptions: RegisterClientOptions, settings: any, video: Video, uriOptions: UriOptions = {} registerOptions: RegisterClientOptions, settings: LiveChatSettings, video: Video, uriOptions: UriOptions = {}
): string | null { ): string | null {
if (!settings) { if (!settings) {
logger.error('Settings are not initialized, too soon to compute the iframeUri') logger.error('Settings are not initialized, too soon to compute the iframeUri')

View File

@ -156,12 +156,12 @@ function launchTests (): void {
'content-type': 'application/json;charset=UTF-8' 'content-type': 'application/json;charset=UTF-8'
}), }),
body: JSON.stringify({ body: JSON.stringify({
test: test test
}) })
}) })
if (!response.ok) { if (!response.ok) {
return { return {
test: test, test,
messages: [response.statusText ?? 'Unknown error'], messages: [response.statusText ?? 'Unknown error'],
ok: false ok: false
} }
@ -169,7 +169,7 @@ function launchTests (): void {
const data = await response.json() const data = await response.json()
if ((typeof data) !== 'object') { if ((typeof data) !== 'object') {
return { return {
test: test, test,
messages: ['Incorrect reponse type: ' + (typeof data)], messages: ['Incorrect reponse type: ' + (typeof data)],
ok: false ok: false
} }
@ -190,6 +190,7 @@ function launchTests (): void {
waiting.innerHTML = '<i>Testing...</i>' waiting.innerHTML = '<i>Testing...</i>'
ul.append(waiting) ul.append(waiting)
if ((typeof result.next) === 'function') { if ((typeof result.next) === 'function') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
const r: Result = (result.next as Function)() const r: Result = (result.next as Function)()
waiting.remove() waiting.remove()
await machine(r) await machine(r)

View File

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/> // SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
import type { RegisterClientOptions } from '@peertube/peertube-types/client' import type { RegisterClientOptions } from '@peertube/peertube-types/client'
import type { InitConverseJSParams, ChatPeertubeIncludeMode } from 'shared/lib/types' import type { InitConverseJSParams, ChatPeertubeIncludeMode } from 'shared/lib/types'
@ -17,7 +18,7 @@ declare global {
} }
} }
let pollListenerInitiliazed: boolean = false let pollListenerInitiliazed = false
/** /**
* load the ConverseJS CSS. * load the ConverseJS CSS.
@ -152,10 +153,11 @@ async function displayConverseJS (
const authHeader = peertubeHelpers.getAuthHeader() const authHeader = peertubeHelpers.getAuthHeader()
const url = getBaseRoute(clientOptions) + '/api/configuration/room/' +
encodeURIComponent(roomKey) +
(forceType ? '?forcetype=1' : '')
const response = await fetch( const response = await fetch(
getBaseRoute(clientOptions) + '/api/configuration/room/' + url,
encodeURIComponent(roomKey) +
(forceType ? '?forcetype=1' : ''),
{ {
method: 'GET', method: 'GET',
headers: authHeader headers: authHeader

View File

@ -4,7 +4,7 @@
import type { RegisterClientOptions } from '@peertube/peertube-types/client' import type { RegisterClientOptions } from '@peertube/peertube-types/client'
function getBaseRoute ({ peertubeHelpers }: RegisterClientOptions, permanent: boolean = false): string { function getBaseRoute ({ peertubeHelpers }: RegisterClientOptions, permanent = false): string {
if (permanent) { if (permanent) {
return '/plugins/livechat/router' return '/plugins/livechat/router'
} }

View File

@ -2,23 +2,30 @@
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
// FIXME:
// * lint shared
// * lint conversejs
// * use eslint-plugin-lit
import love from 'eslint-config-love' import love from 'eslint-config-love'
import eslint from '@eslint/js' import eslint from '@eslint/js'
import tseslint from 'typescript-eslint' import tseslint from 'typescript-eslint'
import typescriptParser from '@typescript-eslint/parser' import typescriptParser from '@typescript-eslint/parser'
import stylistic from '@stylistic/eslint-plugin' import stylistic from '@stylistic/eslint-plugin'
import eslintLit from 'eslint-plugin-lit'
import globals from 'globals' import globals from 'globals'
export default tseslint.config( export default tseslint.config(
{ {
ignores: [ ignores: [
"node_modules/", "dist/", "webpack.config.js", 'node_modules/', 'dist/', 'webpack.config.js',
"build/", 'build/',
"vendor/", 'vendor/',
"support/documentation", "support", 'support/documentation', 'support',
"build-*js", 'build-*js',
"shared", "client", "conversejs" 'shared',
'conversejs'
] ]
}, },
eslint.configs.recommended, eslint.configs.recommended,
@ -27,48 +34,57 @@ export default tseslint.config(
...love, ...love,
files: ['**/*.ts'] files: ['**/*.ts']
}, },
stylistic.configs.customize({
quotes: 'single',
semi: false,
commaDangle: 'never',
blockSpacing: true,
braceStyle: '1tbs',
indent: 2,
quoteProps: 'as-needed'
}),
{ {
plugins: {
'@stylistic': stylistic
},
rules: { rules: {
"@stylistic/semi": ["error", "never"] '@stylistic/space-before-function-paren': ['error', { anonymous: 'always', asyncArrow: 'always', named: 'always' }],
'@stylistic/arrow-parens': 'off',
'@stylistic/operator-linebreak': ['error', 'after', { overrides: { '?': 'before', ':': 'before' } }],
'@stylistic/max-statements-per-line': ['error', { max: 2 }]
} }
}, },
{ {
files: ['**/*.ts'], files: ['**/*.ts'],
rules: { rules: {
"@typescript-eslint/no-empty-function": ["error", {"allow": ["arrowFunctions"]}], '@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }],
"@typescript-eslint/no-unused-vars": [2, {"argsIgnorePattern": "^_", "caughtErrorsIgnorePattern": "^_"}], '@typescript-eslint/no-unused-vars': [2, { argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' }],
"@typescript-eslint/no-floating-promises": "error", '@typescript-eslint/no-floating-promises': 'error',
"@typescript-eslint/no-misused-promises": "error", '@typescript-eslint/no-misused-promises': ['error', { checksVoidReturn: false }],
"@typescript-eslint/no-var-requires": "off", '@typescript-eslint/no-var-requires': 'off',
"@typescript-eslint/strict-boolean-expressions": "off", '@typescript-eslint/strict-boolean-expressions': 'off',
"@typescript-eslint/return-await": [2, "in-try-catch"], // FIXME: correct? '@typescript-eslint/return-await': [2, 'in-try-catch'], // FIXME: correct?
"@typescript-eslint/no-invalid-void-type": "off", '@typescript-eslint/no-invalid-void-type': 'off',
"@typescript-eslint/triple-slash-reference": "off", '@typescript-eslint/triple-slash-reference': 'off',
"@typescript-eslint/no-explicit-any": "off", // FIXME: should be "error", and we should use 'unknown' in the code. '@typescript-eslint/no-explicit-any': 'off', // FIXME: should be "error", and we should use 'unknown' in the code.
"init-declarations": "off", 'init-declarations': 'off',
"@typescript-eslint/init-declarations": "off", '@typescript-eslint/init-declarations': 'off',
"@typescript-eslint/consistent-type-imports": "off", '@typescript-eslint/consistent-type-imports': 'off',
"@typescript-eslint/consistent-type-exports": "off", '@typescript-eslint/consistent-type-exports': 'off',
"@typescript-eslint/no-require-imports": "off", '@typescript-eslint/no-require-imports': 'off',
"@typescript-eslint/unbound-method": "off", '@typescript-eslint/unbound-method': 'off',
"@typescript-eslint/prefer-promise-reject-errors": "off", '@typescript-eslint/prefer-promise-reject-errors': 'off',
"max-params": "off", 'max-params': 'off',
"@typescript-eslint/max-params": ["error", { "max": 8 }], // FIXME: this rules should use the default max value. '@typescript-eslint/max-params': ['error', { max: 8 }], // FIXME: this rules should use the default max value.
"@typescript-eslint/explicit-function-return-type": "error", '@typescript-eslint/explicit-function-return-type': 'error',
"@typescript-eslint/no-confusing-void-expression": "off", '@typescript-eslint/no-confusing-void-expression': 'off',
"@typescript-eslint/class-methods-use-this": "off", '@typescript-eslint/class-methods-use-this': 'off',
"@typescript-eslint/non-nullable-type-assertion-style": "off", '@typescript-eslint/non-nullable-type-assertion-style': 'off',
"max-len": [ 'max-len': [
"error", 'error',
{ {
"code": 120, code: 120,
"comments": 120 comments: 120
} }
], ],
"no-unused-vars": "off" 'no-unused-vars': 'off'
} }
}, },
{ {
@ -90,5 +106,48 @@ export default tseslint.config(
project: './server/tsconfig.json' project: './server/tsconfig.json'
} }
} }
},
{
files: ['shared/**/*.js', 'shared/**/*.ts'], // only ts?
languageOptions: {
ecmaVersion: 6,
globals: {
...globals.es2016,
...globals.browser
},
parser: typescriptParser,
parserOptions: {
ecmaVersion: 2018,
project: [
'./server/tsconfig.json',
'./client/tsconfig.json'
],
projectService: {
allowDefaultProject: 'shared/**/*.ts',
defaultProject: './server/tsconfig.json'
}
}
}
},
{
files: ['client/**/*.js', 'client/**/*.ts'], // only ts?
languageOptions: {
ecmaVersion: 6,
globals: {
...globals.browser
},
parser: typescriptParser,
parserOptions: {
ecmaVersion: 2018,
project: './client/tsconfig.json'
}
},
// FIXME: not sure elintLit works.
plugins: {
...eslintLit.configs['flat/recommended'].plugins
},
rules: {
...eslintLit.configs['flat/recommended'].rules
}
} }
) )

74
package-lock.json generated
View File

@ -43,6 +43,7 @@
"esbuild": "^0.16.1", "esbuild": "^0.16.1",
"eslint": "^8.57.0", "eslint": "^8.57.0",
"eslint-config-love": "^64.0.0", "eslint-config-love": "^64.0.0",
"eslint-plugin-lit": "^1.15.0",
"globals": "^15.9.0", "globals": "^15.9.0",
"lit": "^2.4.0", "lit": "^2.4.0",
"lit-analyzer": "^1.2.1", "lit-analyzer": "^1.2.1",
@ -7045,6 +7046,23 @@
"semver": "bin/semver.js" "semver": "bin/semver.js"
} }
}, },
"node_modules/eslint-plugin-lit": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-lit/-/eslint-plugin-lit-1.15.0.tgz",
"integrity": "sha512-Yhr2MYNz6Ln8megKcX503aVZQln8wsywCG49g0heiJ/Qr5UjkE4pGr4Usez2anNcc7NvlvHbQWMYwWcgH3XRKA==",
"dev": true,
"dependencies": {
"parse5": "^6.0.1",
"parse5-htmlparser2-tree-adapter": "^6.0.1",
"requireindex": "^1.2.0"
},
"engines": {
"node": ">= 12"
},
"peerDependencies": {
"eslint": ">= 5"
}
},
"node_modules/eslint-plugin-n": { "node_modules/eslint-plugin-n": {
"version": "17.10.2", "version": "17.10.2",
"resolved": "https://registry.npmjs.org/eslint-plugin-n/-/eslint-plugin-n-17.10.2.tgz", "resolved": "https://registry.npmjs.org/eslint-plugin-n/-/eslint-plugin-n-17.10.2.tgz",
@ -10954,6 +10972,21 @@
"parse-torrent": "bin/cmd.js" "parse-torrent": "bin/cmd.js"
} }
}, },
"node_modules/parse5": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/parse5/-/parse5-6.0.1.tgz",
"integrity": "sha512-Ofn/CTFzRGTTxwpNEs9PP93gXShHcTq255nzRYSKe8AkVpZY7e1fpmTfOyoIvjP5HG7Z2ZM7VS9PPhQGW2pOpw==",
"dev": true
},
"node_modules/parse5-htmlparser2-tree-adapter": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-6.0.1.tgz",
"integrity": "sha512-qPuWvbLgvDGilKc5BoicRovlT4MtYT6JfJyBOMDsKoiT+GiuP5qyrPCnR9HcPECIJJmZh5jRndyNThnhhb/vlA==",
"dev": true,
"dependencies": {
"parse5": "^6.0.1"
}
},
"node_modules/parseurl": { "node_modules/parseurl": {
"version": "1.3.3", "version": "1.3.3",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
@ -11587,6 +11620,15 @@
"integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==",
"dev": true "dev": true
}, },
"node_modules/requireindex": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.2.0.tgz",
"integrity": "sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==",
"dev": true,
"engines": {
"node": ">=0.10.5"
}
},
"node_modules/requires-port": { "node_modules/requires-port": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
@ -19606,6 +19648,17 @@
} }
} }
}, },
"eslint-plugin-lit": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-lit/-/eslint-plugin-lit-1.15.0.tgz",
"integrity": "sha512-Yhr2MYNz6Ln8megKcX503aVZQln8wsywCG49g0heiJ/Qr5UjkE4pGr4Usez2anNcc7NvlvHbQWMYwWcgH3XRKA==",
"dev": true,
"requires": {
"parse5": "^6.0.1",
"parse5-htmlparser2-tree-adapter": "^6.0.1",
"requireindex": "^1.2.0"
}
},
"eslint-plugin-n": { "eslint-plugin-n": {
"version": "17.10.2", "version": "17.10.2",
"resolved": "https://registry.npmjs.org/eslint-plugin-n/-/eslint-plugin-n-17.10.2.tgz", "resolved": "https://registry.npmjs.org/eslint-plugin-n/-/eslint-plugin-n-17.10.2.tgz",
@ -22304,6 +22357,21 @@
"simple-sha1": "^3.1.0" "simple-sha1": "^3.1.0"
} }
}, },
"parse5": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/parse5/-/parse5-6.0.1.tgz",
"integrity": "sha512-Ofn/CTFzRGTTxwpNEs9PP93gXShHcTq255nzRYSKe8AkVpZY7e1fpmTfOyoIvjP5HG7Z2ZM7VS9PPhQGW2pOpw==",
"dev": true
},
"parse5-htmlparser2-tree-adapter": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-6.0.1.tgz",
"integrity": "sha512-qPuWvbLgvDGilKc5BoicRovlT4MtYT6JfJyBOMDsKoiT+GiuP5qyrPCnR9HcPECIJJmZh5jRndyNThnhhb/vlA==",
"dev": true,
"requires": {
"parse5": "^6.0.1"
}
},
"parseurl": { "parseurl": {
"version": "1.3.3", "version": "1.3.3",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
@ -22753,6 +22821,12 @@
"integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==",
"dev": true "dev": true
}, },
"requireindex": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.2.0.tgz",
"integrity": "sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==",
"dev": true
},
"requires-port": { "requires-port": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",

View File

@ -60,6 +60,7 @@
"esbuild": "^0.16.1", "esbuild": "^0.16.1",
"eslint": "^8.57.0", "eslint": "^8.57.0",
"eslint-config-love": "^64.0.0", "eslint-config-love": "^64.0.0",
"eslint-plugin-lit": "^1.15.0",
"globals": "^15.9.0", "globals": "^15.9.0",
"lit": "^2.4.0", "lit": "^2.4.0",
"lit-analyzer": "^1.2.1", "lit-analyzer": "^1.2.1",
@ -106,8 +107,8 @@
"build": "npm-run-all -s clean:light build:languages check:client:tsc -s build:client build:server build:images build:styles build:avatars build:serverconverse build:prosodymodules build:converse build:prosody", "build": "npm-run-all -s clean:light build:languages check:client:tsc -s build:client build:server build:images build:styles build:avatars build:serverconverse build:prosodymodules build:converse build:prosody",
"lint": "npm-run-all -s lint:script lint:lit lint:styles lint:reuse", "lint": "npm-run-all -s lint:script lint:lit lint:styles lint:reuse",
"lint:fix": "npm-run-all -s lint:script:fix lint:styles:fix", "lint:fix": "npm-run-all -s lint:script:fix lint:styles:fix",
"lint:script": "npx eslint --ext .js --ext .ts .", "lint:script": "npx eslint .",
"lint:script:fix": "npx eslint --ext .js --ext .ts . --fix", "lint:script:fix": "npx eslint . --fix",
"lint:lit": "npx lit-analyzer client/ conversejs/", "lint:lit": "npx lit-analyzer client/ conversejs/",
"lint:styles": "stylelint 'conversejs/**/*.scss' 'assets/styles/**/*.scss'", "lint:styles": "stylelint 'conversejs/**/*.scss' 'assets/styles/**/*.scss'",
"lint:styles:fix": "stylelint 'conversejs/**/*.scss' 'assets/styles/**/*.scss' --fix", "lint:styles:fix": "stylelint 'conversejs/**/*.scss' 'assets/styles/**/*.scss' --fix",

View File

@ -13,7 +13,7 @@ let singleton: BotConfiguration | undefined
type RoomConfCache = type RoomConfCache =
null // already loaded, but file does not exist null // already loaded, but file does not exist
| RoomConf // loaded, and contains the room conf | RoomConf // loaded, and contains the room conf
type ChannelCommonRoomConf = Omit<RoomConf, 'local' | 'domain'> type ChannelCommonRoomConf = Omit<RoomConf, 'local' | 'domain'>

View File

@ -187,8 +187,8 @@ function _getForbiddenWordsHandler (
} else { } else {
// Here we must add word-breaks and escape entries. // Here we must add word-breaks and escape entries.
// We join all entries in one Regexp (for the same reason as above). // We join all entries in one Regexp (for the same reason as above).
rule.regexp = '(?:' + rule.regexp = '(?:' + forbiddenWords.entries.map(
forbiddenWords.entries.map(s => { s => {
s = _stringToWordRegexp(s) s = _stringToWordRegexp(s)
// Must add the \b... // Must add the \b...
// ... but... won't work if the first (or last) char is an emoji. // ... but... won't work if the first (or last) char is an emoji.
@ -201,7 +201,8 @@ function _getForbiddenWordsHandler (
} }
// FIXME: this solution wont work for non-latin charsets. // FIXME: this solution wont work for non-latin charsets.
return s return s
}).join(')|(?:') + ')' }
).join(')|(?:') + ')'
} }
if (forbiddenWords.reason) { if (forbiddenWords.reason) {

View File

@ -234,14 +234,14 @@ async function _connectionInfos (
params: GetConverseJSParamsParams, params: GetConverseJSParamsParams,
roomInfos: RoomInfos roomInfos: RoomInfos
): Promise<{ ): Promise<{
prosodyDomain: string prosodyDomain: string
localAnonymousJID: string localAnonymousJID: string
localBoshUri: string localBoshUri: string
localWsUri: string | null localWsUri: string | null
remoteConnectionInfos: WCRemoteConnectionInfos | undefined remoteConnectionInfos: WCRemoteConnectionInfos | undefined
roomJID: string roomJID: string
customEmojisUrl?: string customEmojisUrl?: string
} | InitConverseJSParamsError> { } | InitConverseJSParamsError> {
const { video, remoteChatInfos, channelId, roomKey } = roomInfos const { video, remoteChatInfos, channelId, roomKey } = roomInfos
const prosodyDomain = await getProsodyDomain(options) const prosodyDomain = await getProsodyDomain(options)

View File

@ -27,11 +27,11 @@ interface DebugContent {
} }
type DebugNumericValue = 'renewCertCheckInterval' type DebugNumericValue = 'renewCertCheckInterval'
| 'renewSelfSignedCertInterval' | 'renewSelfSignedCertInterval'
| 'logRotateEvery' | 'logRotateEvery'
| 'logRotateCheckInterval' | 'logRotateCheckInterval'
| 'remoteServerInfosMaxAge' | 'remoteServerInfosMaxAge'
| 'externalAccountPruneInterval' | 'externalAccountPruneInterval'
type DebugBooleanValue = 'alwaysPublishXMPPRoom' | 'enablePodcastChatTagForNonLive' | 'useOpenSSL' type DebugBooleanValue = 'alwaysPublishXMPPRoom' | 'enablePodcastChatTagForNonLive' | 'useOpenSSL'

View File

@ -48,7 +48,8 @@ export async function diagProsody (test: string, options: RegisterServerOptions)
if (process.arch !== 'x64' && process.arch !== 'x86_64' && process.arch !== 'arm64') { if (process.arch !== 'x64' && process.arch !== 'x86_64' && process.arch !== 'arm64') {
result.messages.push({ result.messages.push({
level: 'error', level: 'error',
message: 'Error: your CPU is a ' + message:
'Error: your CPU is a ' +
process.arch + ', ' + process.arch + ', ' +
'which is not compatible with the plugin. ' + 'which is not compatible with the plugin. ' +
'Please read the plugin installation documentation for a workaround.' 'Please read the plugin installation documentation for a workaround.'

View File

@ -3,8 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
type NextValue = 'backend' | 'debug' | 'webchat-video' | 'prosody' type NextValue = 'backend' | 'debug' | 'webchat-video' | 'prosody'
| 'external-auth-custom-oidc' | 'external-auth-google-oidc' | 'external-auth-facebook-oidc' | 'external-auth-custom-oidc' | 'external-auth-google-oidc' | 'external-auth-facebook-oidc'
| 'everything-ok' | 'everything-ok'
interface MessageWithLevel { interface MessageWithLevel {
level: 'info' | 'warning' | 'error' level: 'info' | 'warning' | 'error'

View File

@ -78,12 +78,13 @@ export class Emojis {
if (!await this.channelHasCustomEmojis(channelId)) { if (!await this.channelHasCustomEmojis(channelId)) {
return undefined return undefined
} }
const route = getBaseRouterRoute(this.options) +
'emojis/channel/' +
encodeURIComponent(channelId) +
'/definition'
return canonicalizePluginUri( return canonicalizePluginUri(
this.options, this.options,
getBaseRouterRoute(this.options) + route,
'emojis/channel/' +
encodeURIComponent(channelId) +
'/definition',
{ {
removePluginVersion: true removePluginVersion: true
} }

View File

@ -289,7 +289,7 @@ function _sanitizePeertubeLiveChatInfosV0 (
logger.debug('We are have to migrate data from the old JSONLD format') logger.debug('We are have to migrate data from the old JSONLD format')
if (chatInfos === false) { return false } if (chatInfos === false) { return false }
if (!_assertObjectType(chatInfos)) { return false} if (!_assertObjectType(chatInfos)) { return false }
if (chatInfos.type !== 'xmpp') { return false } if (chatInfos.type !== 'xmpp') { return false }
if (typeof chatInfos.jid !== 'string') { return false } if (typeof chatInfos.jid !== 'string') { return false }

View File

@ -529,7 +529,7 @@ function initThemingSettings ({ registerSetting }: RegisterServerOptions): void
{ value: 'peertube', label: loc('converse_theme_option_peertube') }, { value: 'peertube', label: loc('converse_theme_option_peertube') },
{ value: 'default', label: loc('converse_theme_option_default') }, { value: 'default', label: loc('converse_theme_option_default') },
{ value: 'cyberpunk', label: loc('converse_theme_option_cyberpunk') } { value: 'cyberpunk', label: loc('converse_theme_option_cyberpunk') }
] as Array<{value: ConverseJSTheme, label: string}>, ] as Array<{ value: ConverseJSTheme, label: string }>,
descriptionHTML: loc('converse_theme_description') descriptionHTML: loc('converse_theme_description')
}) })