From 0ce95d4a39dbd920511b80525fd6785576d456d2 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Fri, 21 Apr 2023 17:24:16 +0200 Subject: [PATCH] Chat Federation: don't display chat when anonymous connections are disabled --- server/lib/custom-fields.ts | 5 ++++ server/lib/federation/outgoing.ts | 38 +++++++++++++++++-------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/server/lib/custom-fields.ts b/server/lib/custom-fields.ts index eb491296..edf7c3d0 100644 --- a/server/lib/custom-fields.ts +++ b/server/lib/custom-fields.ts @@ -1,5 +1,6 @@ import type { RegisterServerOptions, Video, MVideoThumbnail } from '@peertube/peertube-types' import { getVideoLiveChatInfos } from './federation/storage' +import { anonymousConnectionInfos } from './federation/connection-infos' async function initCustomFields (options: RegisterServerOptions): Promise { const registerHook = options.registerHook @@ -83,6 +84,10 @@ async function fillVideoRemoteLiveChat ( const infos = await getVideoLiveChatInfos(options, video) if (!infos) { return } + // We must check if there is a compatible connection protocol... + // For now, the only that is implemetied is by using a remote anonymous account. + if (!anonymousConnectionInfos(infos)) { return } + const v: LiveChatCustomFieldsVideo = video if (!v.pluginData) v.pluginData = {} v.pluginData['livechat-remote'] = true diff --git a/server/lib/federation/outgoing.ts b/server/lib/federation/outgoing.ts index 27248ee1..4e1df453 100644 --- a/server/lib/federation/outgoing.ts +++ b/server/lib/federation/outgoing.ts @@ -29,7 +29,8 @@ async function videoBuildJSONLD ( 'chat-videos-list', 'disable-websocket', 'prosody-room-type', - 'federation-dont-publish-remotely' + 'federation-dont-publish-remotely', + 'chat-no-anonymous' ]) if (settings['federation-dont-publish-remotely']) { @@ -66,22 +67,25 @@ async function videoBuildJSONLD ( roomJID = `${video.uuid}@room.${prosodyDomain}` } - const links: LiveChatJSONLDLink[] = [{ - type: 'xmpp-bosh-anonymous', - url: canonicalizePluginUri(options, getBoshUri(options), { removePluginVersion: true }), - jid: userJID - }] - if (!settings['disable-websocket']) { - const wsUri = getWSUri(options) - if (wsUri) { - links.push({ - type: 'xmpp-websocket-anonymous', - url: canonicalizePluginUri(options, wsUri, { - removePluginVersion: true, - protocol: 'ws' - }), - jid: userJID - }) + const links: LiveChatJSONLDLink[] = [] + if (!settings['chat-no-anonymous']) { + links.push({ + type: 'xmpp-bosh-anonymous', + url: canonicalizePluginUri(options, getBoshUri(options), { removePluginVersion: true }), + jid: userJID + }) + if (!settings['disable-websocket']) { + const wsUri = getWSUri(options) + if (wsUri) { + links.push({ + type: 'xmpp-websocket-anonymous', + url: canonicalizePluginUri(options, wsUri, { + removePluginVersion: true, + protocol: 'ws' + }), + jid: userJID + }) + } } }