Link to channel options in room list
This commit is contained in:
parent
eed88e9339
commit
567a5e80ab
@ -78,6 +78,8 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re
|
|||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Response is not ok')
|
throw new Error('Response is not ok')
|
||||||
}
|
}
|
||||||
|
const settings = await peertubeHelpers.getSettings()
|
||||||
|
const useChannelConfiguration = !(settings['disable-channel-configuration'])
|
||||||
const json: ProsodyListRoomsResult = await response.json()
|
const json: ProsodyListRoomsResult = await response.json()
|
||||||
if (!json.ok) {
|
if (!json.ok) {
|
||||||
container.textContent = json.error
|
container.textContent = json.error
|
||||||
@ -105,7 +107,8 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re
|
|||||||
NotFound: await peertubeHelpers.translate(LOC_NOT_FOUND),
|
NotFound: await peertubeHelpers.translate(LOC_NOT_FOUND),
|
||||||
Video: await peertubeHelpers.translate(LOC_VIDEO),
|
Video: await peertubeHelpers.translate(LOC_VIDEO),
|
||||||
Channel: await peertubeHelpers.translate(LOC_CHANNEL),
|
Channel: await peertubeHelpers.translate(LOC_CHANNEL),
|
||||||
LastActivity: await peertubeHelpers.translate(LOC_LAST_ACTIVITY)
|
LastActivity: await peertubeHelpers.translate(LOC_LAST_ACTIVITY),
|
||||||
|
channelConfiguration: await peertubeHelpers.translate(LOC_LIVECHAT_CONFIGURATION_CHANNEL_TITLE)
|
||||||
}
|
}
|
||||||
|
|
||||||
const titleLineEl = document.createElement('tr')
|
const titleLineEl = document.createElement('tr')
|
||||||
@ -121,6 +124,11 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re
|
|||||||
titleLineEl.append(titleDescriptionEl)
|
titleLineEl.append(titleDescriptionEl)
|
||||||
titleLineEl.append(titleVideoEl)
|
titleLineEl.append(titleVideoEl)
|
||||||
titleLineEl.append(titleLastActivityEl)
|
titleLineEl.append(titleLastActivityEl)
|
||||||
|
if (useChannelConfiguration) {
|
||||||
|
const titleChannelConfiguration = document.createElement('th')
|
||||||
|
titleChannelConfiguration.textContent = labels.channelConfiguration
|
||||||
|
titleLineEl.append(titleChannelConfiguration)
|
||||||
|
}
|
||||||
table.append(titleLineEl)
|
table.append(titleLineEl)
|
||||||
rooms.forEach(room => {
|
rooms.forEach(room => {
|
||||||
const localpart = room.localpart
|
const localpart = room.localpart
|
||||||
@ -137,13 +145,24 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re
|
|||||||
const date = new Date(room.lasttimestamp * 1000)
|
const date = new Date(room.lasttimestamp * 1000)
|
||||||
lastActivityEl.textContent = date.toLocaleDateString() + ' ' + date.toLocaleTimeString()
|
lastActivityEl.textContent = date.toLocaleDateString() + ' ' + date.toLocaleTimeString()
|
||||||
}
|
}
|
||||||
|
const channelConfigurationEl = document.createElement('td')
|
||||||
nameEl.append(aEl)
|
nameEl.append(aEl)
|
||||||
lineEl.append(nameEl)
|
lineEl.append(nameEl)
|
||||||
lineEl.append(descriptionEl)
|
lineEl.append(descriptionEl)
|
||||||
lineEl.append(videoEl)
|
lineEl.append(videoEl)
|
||||||
lineEl.append(lastActivityEl)
|
lineEl.append(lastActivityEl)
|
||||||
|
if (useChannelConfiguration) {
|
||||||
|
lineEl.append(channelConfigurationEl) // else the element will just be dropped.
|
||||||
|
}
|
||||||
table.append(lineEl)
|
table.append(lineEl)
|
||||||
|
|
||||||
|
const writeChannelConfigurationLink = (channelId: number | string): void => {
|
||||||
|
const a = document.createElement('a')
|
||||||
|
a.href = '/p/livechat/configuration/channel?channelId=' + encodeURIComponent(channelId)
|
||||||
|
a.textContent = labels.channelConfiguration
|
||||||
|
channelConfigurationEl.append(a)
|
||||||
|
}
|
||||||
|
|
||||||
const channelMatches = localpart.match(/^channel\.(\d+)$/)
|
const channelMatches = localpart.match(/^channel\.(\d+)$/)
|
||||||
if (channelMatches) {
|
if (channelMatches) {
|
||||||
// Here we have a channel chat room
|
// Here we have a channel chat room
|
||||||
@ -158,6 +177,9 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re
|
|||||||
aVideoEl.href = '/video-channels/' + room.channel.name
|
aVideoEl.href = '/video-channels/' + room.channel.name
|
||||||
videoEl.append(aVideoEl)
|
videoEl.append(aVideoEl)
|
||||||
}
|
}
|
||||||
|
if (room.channel?.id) {
|
||||||
|
writeChannelConfigurationLink(room.channel.id)
|
||||||
|
}
|
||||||
} else if (/^[a-zA-A0-9-]+$/.test(localpart)) {
|
} else if (/^[a-zA-A0-9-]+$/.test(localpart)) {
|
||||||
// localpart must be a video uuid.
|
// localpart must be a video uuid.
|
||||||
const uuid = localpart
|
const uuid = localpart
|
||||||
@ -183,6 +205,9 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re
|
|||||||
aVideoEl.target = '_blank'
|
aVideoEl.target = '_blank'
|
||||||
aVideoEl.href = '/videos/watch/' + uuid
|
aVideoEl.href = '/videos/watch/' + uuid
|
||||||
videoEl.append(aVideoEl)
|
videoEl.append(aVideoEl)
|
||||||
|
if (video.channel.id) {
|
||||||
|
writeChannelConfigurationLink(video.channel.id)
|
||||||
|
}
|
||||||
}, () => {
|
}, () => {
|
||||||
console.error('[peertube-plugin-livechat] Failed to retrieve video ' + uuid)
|
console.error('[peertube-plugin-livechat] Failed to retrieve video ' + uuid)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user