2024-05-23 09:42:14 +00:00
|
|
|
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2022-01-07 18:20:28 +00:00
|
|
|
import { __ } from 'i18n'
|
2024-07-11 15:53:50 +00:00
|
|
|
import { _converse, api } from '@converse/headless'
|
2022-01-07 18:20:28 +00:00
|
|
|
import { html } from 'lit'
|
|
|
|
import tplMucBottomPanel from '../../src/plugins/muc-views/templates/muc-bottom-panel.js'
|
2024-02-16 13:34:34 +00:00
|
|
|
import { CustomElement } from 'shared/components/element.js'
|
2024-04-08 17:02:56 +00:00
|
|
|
import 'shared/modals/livechat-external-login.js'
|
2022-01-07 18:20:28 +00:00
|
|
|
|
|
|
|
async function setNickname (ev, model) {
|
|
|
|
ev.preventDefault()
|
|
|
|
const nick = ev.target.nick.value.trim()
|
2024-01-09 11:54:30 +00:00
|
|
|
if (!nick) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
await model.setNickname(nick)
|
|
|
|
_converse.api.trigger('livechatViewerModeSetNickname', model, nick, {
|
|
|
|
synchronous: true
|
|
|
|
})
|
2022-01-07 18:20:28 +00:00
|
|
|
}
|
|
|
|
|
2024-02-16 13:34:34 +00:00
|
|
|
class SlowMode extends CustomElement {
|
|
|
|
static get properties () {
|
|
|
|
return {
|
|
|
|
jid: { type: String }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-16 14:44:39 +00:00
|
|
|
hideInfoBox = false
|
|
|
|
|
2024-02-16 13:34:34 +00:00
|
|
|
async connectedCallback () {
|
|
|
|
super.connectedCallback()
|
|
|
|
this.model = _converse.chatboxes.get(this.jid)
|
|
|
|
await this.model.initialized
|
|
|
|
|
2024-02-16 14:44:39 +00:00
|
|
|
let previousDuration = this.model.config.get('slow_mode_duration')
|
2024-02-16 14:16:44 +00:00
|
|
|
this.listenTo(this.model.config, 'change:slow_mode_duration', () => {
|
2024-02-16 14:44:39 +00:00
|
|
|
if (this.hideInfoBox) {
|
|
|
|
const duration = this.model.config.get('slow_mode_duration')
|
|
|
|
if (duration !== previousDuration) {
|
|
|
|
previousDuration = duration
|
|
|
|
// Duration changed, opening the infobox again.
|
|
|
|
this.hideInfoBox = false
|
|
|
|
}
|
|
|
|
}
|
2024-02-16 13:34:34 +00:00
|
|
|
this.requestUpdate()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2024-02-16 14:16:44 +00:00
|
|
|
if (!(parseInt(this.model.config.get('slow_mode_duration')) > 0)) { // This includes NaN, for which ">0"===false
|
2024-02-16 13:34:34 +00:00
|
|
|
return html``
|
|
|
|
}
|
2024-02-16 14:44:39 +00:00
|
|
|
if (this.hideInfoBox) {
|
|
|
|
return html``
|
|
|
|
}
|
2024-02-22 15:05:12 +00:00
|
|
|
return html`<div class="livechat-slow-mode-info-box">
|
2024-02-16 13:34:34 +00:00
|
|
|
<converse-icon class="fa fa-info-circle" size="1.2em"></converse-icon>
|
|
|
|
${__(
|
2024-04-08 17:02:56 +00:00
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
LOC_slow_mode_info,
|
2024-02-16 14:16:44 +00:00
|
|
|
this.model.config.get('slow_mode_duration')
|
2024-02-16 14:44:39 +00:00
|
|
|
)}
|
2024-06-25 07:59:46 +00:00
|
|
|
<i class="livechat-hide-slow-mode-info-box" @click=${this.closeSlowModeInfoBox} title=${__('Close')}>
|
2024-02-16 14:44:39 +00:00
|
|
|
<converse-icon class="fa fa-times" size="1em"></converse-icon>
|
2024-02-22 15:05:12 +00:00
|
|
|
</i>
|
|
|
|
</div>`
|
2024-02-16 14:44:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
closeSlowModeInfoBox (ev) {
|
|
|
|
ev?.preventDefault?.()
|
|
|
|
ev?.stopPropagation?.()
|
|
|
|
this.hideInfoBox = true
|
|
|
|
this.requestUpdate()
|
2024-02-16 13:34:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
api.elements.define('livechat-slow-mode', SlowMode)
|
|
|
|
|
|
|
|
const tplSlowMode = (o) => {
|
2024-07-15 12:20:44 +00:00
|
|
|
if (!o.can_post) { return html`` }
|
2024-02-16 13:34:34 +00:00
|
|
|
return html`<livechat-slow-mode jid=${o.model.get('jid')}>`
|
|
|
|
}
|
|
|
|
|
2024-06-20 14:46:14 +00:00
|
|
|
const tplViewerMode = (o) => {
|
|
|
|
if (!api.settings.get('livechat_enable_viewer_mode')) {
|
|
|
|
return html``
|
|
|
|
}
|
|
|
|
const model = o.model
|
|
|
|
const i18nNickname = __('Nickname')
|
|
|
|
const i18nJoin = __('Enter groupchat')
|
|
|
|
const i18nHeading = __('Choose a nickname to enter')
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
const i18nExternalLogin = __(LOC_login_using_external_account)
|
|
|
|
return html`
|
2024-04-08 17:02:56 +00:00
|
|
|
<div class="livechat-viewer-mode-content chatroom-form-container">
|
|
|
|
<form class="converse-form chatroom-form" @submit=${ev => setNickname(ev, model)}>
|
2024-04-03 09:18:00 +00:00
|
|
|
<label>${i18nHeading}</label>
|
2024-08-05 13:54:03 +00:00
|
|
|
<fieldset>
|
2024-01-09 15:55:13 +00:00
|
|
|
<input type="text"
|
2024-04-08 17:02:56 +00:00
|
|
|
required
|
2024-01-09 15:55:13 +00:00
|
|
|
name="nick"
|
|
|
|
value=""
|
|
|
|
class="form-control"
|
|
|
|
placeholder="${i18nNickname}"/>
|
2022-01-07 18:20:28 +00:00
|
|
|
</fieldset>
|
2024-08-05 13:54:03 +00:00
|
|
|
<fieldset>
|
2022-01-07 18:20:28 +00:00
|
|
|
<input type="submit" class="btn btn-primary" name="join" value="${i18nJoin}"/>
|
|
|
|
</fieldset>
|
|
|
|
</form>
|
2024-04-08 17:02:56 +00:00
|
|
|
${
|
|
|
|
// If we open a room with forcetype, there is no current video... So just disabling external login
|
|
|
|
// (in such case, we should be logged in as admin/moderator...)
|
|
|
|
!api.settings.get('livechat_peertube_video_original_url')
|
|
|
|
? ''
|
|
|
|
: html`
|
|
|
|
<hr>
|
|
|
|
<div class="livechat-viewer-mode-external-login">
|
|
|
|
<button class="btn btn-primary" @click=${ev => {
|
|
|
|
ev.preventDefault()
|
|
|
|
api.modal.show('converse-livechat-external-login')
|
|
|
|
}}>${i18nExternalLogin}</button>
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
}
|
2024-06-20 14:46:14 +00:00
|
|
|
</div>`
|
|
|
|
}
|
|
|
|
|
|
|
|
export default (o) => {
|
|
|
|
let mutedAnonymousMessage
|
|
|
|
if (
|
2024-07-15 12:20:44 +00:00
|
|
|
!o.can_post &&
|
2024-06-20 14:46:14 +00:00
|
|
|
o.model.features?.get?.('x_peertubelivechat_mute_anonymous') &&
|
|
|
|
_converse.api.settings.get('livechat_specific_is_anonymous') === true
|
|
|
|
) {
|
|
|
|
// If we are moderated because we are anonymous, we want to display a custom message.
|
|
|
|
// FIXME: if x_peertubelivechat_mute_anonymous changes, user are first muted/voiced, and then only the
|
|
|
|
// status 104 is sent. But we don't listen to 'change:x_peertubelivechat_mute_anonymous'.
|
|
|
|
// So the custom message won't be correct. But this is not a big issue.
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
mutedAnonymousMessage = __(LOC_muted_anonymous_message)
|
2022-01-07 18:20:28 +00:00
|
|
|
}
|
2024-02-16 13:34:34 +00:00
|
|
|
|
|
|
|
return html`
|
2024-06-20 14:46:14 +00:00
|
|
|
${tplViewerMode(o)}
|
2024-02-16 13:34:34 +00:00
|
|
|
${tplSlowMode(o)}
|
2024-06-20 14:46:14 +00:00
|
|
|
${
|
|
|
|
mutedAnonymousMessage
|
|
|
|
? html`<span class="muc-bottom-panel muc-bottom-panel--muted">${mutedAnonymousMessage}</span>`
|
|
|
|
: tplMucBottomPanel(o)
|
|
|
|
}`
|
2022-01-07 18:20:28 +00:00
|
|
|
}
|