diff --git a/client/videowatch-client-plugin.ts b/client/videowatch-client-plugin.ts index 69aa6e98..73ccc3a4 100644 --- a/client/videowatch-client-plugin.ts +++ b/client/videowatch-client-plugin.ts @@ -1,6 +1,6 @@ import type { Video } from '@peertube/peertube-types' import type { RegisterClientOptions } from '@peertube/peertube-types/client' -import { videoHasWebchat } from 'shared/lib/video' +import { videoHasWebchat, videoHasRemoteWebchat } from 'shared/lib/video' import { logger } from './videowatch/logger' import { closeSVG, openBlankChatSVG, openChatSVG, shareChatUrlSVG } from './videowatch/buttons' import { displayButton, displayButtonOptions } from './videowatch/button' @@ -247,19 +247,21 @@ function register (registerOptions: RegisterClientOptions): void { logger.log('No chat for anonymous users') return } - if (!videoHasWebchat(s, video)) { + if (!videoHasWebchat(s, video) && !videoHasRemoteWebchat(s, video)) { logger.log('This video has no webchat') return } let showShareUrlButton: boolean = false - const chatShareUrl = settings['chat-share-url'] ?? '' - if (chatShareUrl === 'everyone') { - showShareUrlButton = true - } else if (chatShareUrl === 'owner') { - showShareUrlButton = guessIsMine(registerOptions, video) - } else if (chatShareUrl === 'owner+moderators') { - showShareUrlButton = guessIsMine(registerOptions, video) || guessIamIModerator(registerOptions) + if (video.isLocal) { // No need for shareButton on remote chats. + const chatShareUrl = settings['chat-share-url'] ?? '' + if (chatShareUrl === 'everyone') { + showShareUrlButton = true + } else if (chatShareUrl === 'owner') { + showShareUrlButton = guessIsMine(registerOptions, video) + } else if (chatShareUrl === 'owner+moderators') { + showShareUrlButton = guessIsMine(registerOptions, video) || guessIamIModerator(registerOptions) + } } insertChatDom(container as HTMLElement, video, !!settings['chat-open-blank'], showShareUrlButton).then(() => { diff --git a/conversejs/builtin.ts b/conversejs/builtin.ts index 88891979..d2e1ce6d 100644 --- a/conversejs/builtin.ts +++ b/conversejs/builtin.ts @@ -82,6 +82,7 @@ function randomNick (base: string): string { interface InitConverseParams { jid: string + remoteAnonymousXMPPServer: boolean assetsPath: string room: string boshServiceUrl: string @@ -95,6 +96,7 @@ interface InitConverseParams { } window.initConverse = async function initConverse ({ jid, + remoteAnonymousXMPPServer, assetsPath, room, boshServiceUrl, @@ -205,6 +207,7 @@ window.initConverse = async function initConverse ({ // TODO: params.clear_messages_on_reconnection = true when muc_mam will be available. let isAuthenticated: boolean = false + let isRemoteWithNicknameSet: boolean = false if (authenticationUrl === '') { throw new Error('Missing authenticationUrl') } @@ -218,19 +221,27 @@ window.initConverse = async function initConverse ({ const auth = await authenticatedMode(authenticationUrl) if (auth) { - params.authentication = 'login' - params.auto_login = true - params.jid = auth.jid - params.password = auth.password - if (auth.nickname) { - params.nickname = auth.nickname + if (remoteAnonymousXMPPServer) { + // Spécial case: anonymous connection to remote XMPP server. + if (auth.nickname) { + params.nickname = auth.nickname + isRemoteWithNicknameSet = true + } } else { - params.muc_nickname_from_jid = true + params.authentication = 'login' + params.auto_login = true + params.jid = auth.jid + params.password = auth.password + if (auth.nickname) { + params.nickname = auth.nickname + } else { + params.muc_nickname_from_jid = true + } + // We dont need the keepalive. And I suppose it is related to some bugs when opening a previous chat window. + params.keepalive = false + isAuthenticated = true + // FIXME: use params.oauth_providers? } - // We dont need the keepalive. And I suppose it is related to some bugs when opening a previous chat window. - params.keepalive = false - isAuthenticated = true - // FIXME: use params.oauth_providers? } if (!isAuthenticated) { @@ -267,7 +278,7 @@ window.initConverse = async function initConverse ({ } }) - if (autoViewerMode && !isAuthenticated) { + if (autoViewerMode && !isAuthenticated && !isRemoteWithNicknameSet) { converse.plugins.add('livechatViewerModePlugin', { dependencies: ['converse-muc', 'converse-muc-views'], initialize: function () { diff --git a/conversejs/index.html b/conversejs/index.html index bab4e7f1..bdb921a2 100644 --- a/conversejs/index.html +++ b/conversejs/index.html @@ -16,6 +16,7 @@