@ -16,7 +16,6 @@ export function tplTokenList (el: LivechatTokenListElement): TemplateResult {
|
||||
<tr>
|
||||
<th scope="col"></th>
|
||||
<th scope="col">${ptTr(LOC_TOKEN_LABEL)}</th>
|
||||
<th scope="col">${ptTr(LOC_TOKEN_JID)}</th>
|
||||
<th scope="col">${ptTr(LOC_TOKEN_PASSWORD)}</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
@ -24,19 +23,29 @@ export function tplTokenList (el: LivechatTokenListElement): TemplateResult {
|
||||
<tbody>
|
||||
${
|
||||
repeat(el.tokenList ?? [], (token) => token.id, (token) => {
|
||||
html`<tr>
|
||||
return html`<tr>
|
||||
<td>${
|
||||
el.mode === 'select'
|
||||
? html`<input
|
||||
type="radio"
|
||||
?selected=${el.currentSelectedToken?.id === token.id}
|
||||
@click=${el.selectToken}
|
||||
name="livechat-token"
|
||||
value=${token.id}
|
||||
id=${`livechat-token-radio-${token.id}`}
|
||||
?checked=${el.currentSelectedToken?.id === token.id}
|
||||
@click=${(ev: Event) => el.selectToken(ev, token)}
|
||||
/>`
|
||||
: ''
|
||||
}</td>
|
||||
<td>${token.label}</td>
|
||||
<td>${token.jid}</td>
|
||||
<td>${token.password}</td>
|
||||
<td>
|
||||
<label for=${`livechat-token-radio-${token.id}`}>
|
||||
${token.label}
|
||||
</label>
|
||||
</td>
|
||||
<td>
|
||||
<label for=${`livechat-token-radio-${token.id}`}>
|
||||
${token.password}
|
||||
</label>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button"
|
||||
class="livechat-revoke-token"
|
||||
|
@ -42,6 +42,10 @@ export class LivechatTokenListElement extends LivechatElement {
|
||||
return new Task(this, {
|
||||
task: async () => {
|
||||
this.tokenList = await this._tokenListService.fetchTokenList()
|
||||
if (this.mode === 'select' && this.tokenList.length) {
|
||||
this.currentSelectedToken = this.tokenList[0]
|
||||
this.dispatchEvent(new CustomEvent('update', {}))
|
||||
}
|
||||
this.actionDisabled = false
|
||||
},
|
||||
args: () => []
|
||||
@ -57,13 +61,17 @@ export class LivechatTokenListElement extends LivechatElement {
|
||||
}
|
||||
|
||||
public selectToken (ev: Event, token: LivechatToken): void {
|
||||
ev.preventDefault()
|
||||
if (!this.tokenList?.includes(token)) { return }
|
||||
this.currentSelectedToken = token
|
||||
this.requestUpdate('tokenList')
|
||||
this.dispatchEvent(new CustomEvent('update', {}))
|
||||
}
|
||||
|
||||
public async revokeToken (token: LivechatToken): Promise<void> {
|
||||
const confirmMsg = await this.ptTranslate(LOC_TOKEN_ACTION_REVOKE_CONFIRM)
|
||||
// Note: we can't use peertube showModal to confirm if we already are in a modal...
|
||||
if (!window.confirm(confirmMsg)) { return }
|
||||
|
||||
this.actionDisabled = true
|
||||
try {
|
||||
await this._tokenListService.revokeToken(token)
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
import type { Video } from '@peertube/peertube-types'
|
||||
import type { LiveChatSettings } from '../../lib/contexts/peertube'
|
||||
import type { LivechatTokenListElement } from '../../lib/elements/token-list'
|
||||
import { html, PropertyValues, TemplateResult } from 'lit'
|
||||
import { customElement, property } from 'lit/decorators.js'
|
||||
import { LivechatElement } from '../../lib/elements/livechat'
|
||||
@ -222,29 +223,37 @@ export class ShareChatElement extends LivechatElement {
|
||||
}
|
||||
|
||||
protected _computeUrlDock (): ComputedUrl {
|
||||
return {
|
||||
shareString: '',
|
||||
openUrl: undefined
|
||||
const tokenList: LivechatTokenListElement | null = this.querySelector('livechat-token-list')
|
||||
const token = tokenList?.currentSelectedToken
|
||||
if (!token) {
|
||||
return {
|
||||
shareString: '',
|
||||
openUrl: undefined
|
||||
}
|
||||
}
|
||||
const uriOptions: UriOptions = {
|
||||
ignoreAutoColors: true,
|
||||
permanent: true
|
||||
}
|
||||
// const uriOptions: UriOptions = {
|
||||
// ignoreAutoColors: true,
|
||||
// permanent: true
|
||||
// }
|
||||
|
||||
// // Note: for the "embed" case, the url is always the same as the iframe.
|
||||
// // So we use getIframeUri to compte, and just change the finale result if we really want the iframe.
|
||||
// const url = getIframeUri(this.ptContext.ptOptions, this._settings, this._video, uriOptions)
|
||||
// if (!url) {
|
||||
// return {
|
||||
// shareString: '',
|
||||
// openUrl: undefined
|
||||
// }
|
||||
// }
|
||||
let url = getIframeUri(this.ptContext.ptOptions, this._settings, this._video, uriOptions)
|
||||
if (!url) {
|
||||
return {
|
||||
shareString: '',
|
||||
openUrl: undefined
|
||||
}
|
||||
}
|
||||
|
||||
// return {
|
||||
// shareString: url,
|
||||
// openUrl: url
|
||||
// }
|
||||
url += '#?p=' + encodeURIComponent(token.password)
|
||||
url += '&j=' + encodeURIComponent(token.jid)
|
||||
if (token.nickname) {
|
||||
url += '&n=' + encodeURIComponent(token.nickname)
|
||||
}
|
||||
|
||||
return {
|
||||
shareString: url,
|
||||
openUrl: url
|
||||
}
|
||||
}
|
||||
|
||||
protected _computeUrlEmbed (): ComputedUrl {
|
||||
|
@ -167,8 +167,13 @@ function _tplShareChatEmbedOptions (el: ShareChatElement): TemplateResult {
|
||||
`
|
||||
}
|
||||
|
||||
function _tplShareChatDockOptions (_el: ShareChatElement): TemplateResult {
|
||||
return html`<livechat-token-list mode="select"></livechat-token-list>`
|
||||
function _tplShareChatDockOptions (el: ShareChatElement): TemplateResult {
|
||||
return html`<livechat-token-list
|
||||
mode="select"
|
||||
@update=${(_e: CustomEvent) => {
|
||||
el.requestUpdate()
|
||||
}}
|
||||
></livechat-token-list>`
|
||||
}
|
||||
|
||||
function _tplShareChatXMPPOptions (_el: ShareChatElement): TemplateResult {
|
||||
|
Reference in New Issue
Block a user