2024-05-23 09:42:14 +00:00
|
|
|
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
|
2024-05-23 15:17:28 +00:00
|
|
|
// SPDX-FileCopyrightText: 2024 Mehdi Benadel <https://mehdibenadel.com>
|
2024-05-23 09:42:14 +00:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-08-08 15:15:05 +00:00
|
|
|
import type { RegisterClientOptions } from '@peertube/peertube-types/client'
|
2024-05-13 14:40:36 +00:00
|
|
|
import { html, render } from 'lit'
|
2024-05-23 14:56:11 +00:00
|
|
|
import './elements' // Import all needed elements.
|
2023-08-08 15:15:05 +00:00
|
|
|
|
2023-08-08 16:26:40 +00:00
|
|
|
/**
|
2023-09-06 13:23:39 +00:00
|
|
|
* Registers stuff related to the user's configuration pages.
|
2023-08-08 16:26:40 +00:00
|
|
|
* @param clientOptions Peertube client options
|
|
|
|
*/
|
2023-09-06 13:23:39 +00:00
|
|
|
async function registerConfiguration (clientOptions: RegisterClientOptions): Promise<void> {
|
2023-08-08 15:15:05 +00:00
|
|
|
const { peertubeHelpers, registerClientRoute, registerHook } = clientOptions
|
|
|
|
|
2023-09-06 13:56:55 +00:00
|
|
|
const settings = await peertubeHelpers.getSettings()
|
2023-09-18 16:53:07 +00:00
|
|
|
if (settings['disable-channel-configuration']) { return }
|
2023-09-06 13:56:55 +00:00
|
|
|
|
2023-08-08 15:15:05 +00:00
|
|
|
registerClientRoute({
|
2023-09-06 13:23:39 +00:00
|
|
|
route: 'livechat/configuration',
|
2023-08-08 15:15:05 +00:00
|
|
|
onMount: async ({ rootEl }) => {
|
2024-05-23 13:52:12 +00:00
|
|
|
render(html`<livechat-channel-home .registerClientOptions=${clientOptions}></livechat-channel-home>`, rootEl)
|
2023-08-08 15:15:05 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-08-08 16:26:40 +00:00
|
|
|
registerClientRoute({
|
2023-09-06 13:23:39 +00:00
|
|
|
route: 'livechat/configuration/channel',
|
2023-08-08 16:26:40 +00:00
|
|
|
onMount: async ({ rootEl }) => {
|
|
|
|
const urlParams = new URLSearchParams(window.location.search)
|
2024-06-12 16:51:04 +00:00
|
|
|
const channelId = parseInt(urlParams.get('channelId') ?? '')
|
|
|
|
if (isNaN(channelId)) { throw new Error('Invalid channelId parameter') }
|
|
|
|
render(html`
|
|
|
|
<livechat-channel-configuration
|
|
|
|
.registerClientOptions=${clientOptions}
|
|
|
|
.channelId=${channelId}></livechat-channel-configuration
|
|
|
|
></livechat-channel-configuration>
|
|
|
|
`, rootEl)
|
2023-08-08 16:26:40 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-05-28 15:56:24 +00:00
|
|
|
registerClientRoute({
|
|
|
|
route: 'livechat/configuration/emojis',
|
|
|
|
onMount: async ({ rootEl }) => {
|
|
|
|
const urlParams = new URLSearchParams(window.location.search)
|
2024-06-12 16:51:04 +00:00
|
|
|
const channelId = parseInt(urlParams.get('channelId') ?? '')
|
|
|
|
if (isNaN(channelId)) { throw new Error('Invalid channelId parameter') }
|
2024-05-28 15:56:24 +00:00
|
|
|
render(html`
|
|
|
|
<livechat-channel-emojis
|
|
|
|
.registerClientOptions=${clientOptions}
|
|
|
|
.channelId=${channelId}
|
|
|
|
></livechat-channel-emojis>
|
|
|
|
`, rootEl)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-08-08 15:15:05 +00:00
|
|
|
registerHook({
|
|
|
|
target: 'filter:left-menu.links.create.result',
|
|
|
|
handler: async (links: any) => {
|
2023-09-06 13:23:39 +00:00
|
|
|
// Adding the links to livechat/configuration for logged users.
|
2023-08-08 15:15:05 +00:00
|
|
|
if (!peertubeHelpers.isLoggedIn()) { return links }
|
|
|
|
|
|
|
|
if (!Array.isArray(links)) { return links }
|
|
|
|
let myLibraryLinks
|
|
|
|
// Searching the 'in-my-library' entry.
|
|
|
|
for (const link of links) {
|
|
|
|
if (typeof link !== 'object') { continue }
|
|
|
|
if (!('key' in link)) { continue }
|
|
|
|
if (link.key !== 'in-my-library') { continue }
|
|
|
|
myLibraryLinks = link
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if (!myLibraryLinks) { return links }
|
|
|
|
if (!Array.isArray(myLibraryLinks.links)) { return links }
|
|
|
|
|
2023-09-06 13:23:39 +00:00
|
|
|
const label = await peertubeHelpers.translate(LOC_MENU_CONFIGURATION_LABEL)
|
2023-08-08 15:15:05 +00:00
|
|
|
myLibraryLinks.links.push({
|
|
|
|
label,
|
|
|
|
shortLabel: label,
|
2023-09-06 13:23:39 +00:00
|
|
|
path: '/p/livechat/configuration',
|
2023-08-08 15:15:05 +00:00
|
|
|
icon: 'live'
|
|
|
|
})
|
|
|
|
return links
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
2023-09-06 13:23:39 +00:00
|
|
|
registerConfiguration
|
2023-08-08 15:15:05 +00:00
|
|
|
}
|