From a026c57cc31aa192fa077fce0dedabef9f5ade82 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Sun, 5 May 2024 12:47:33 +0200 Subject: [PATCH] The livechat plugin broke the federation with Peertube >= 6.1.0. --- CHANGELOG.md | 4 ++++ server/lib/federation/init.ts | 15 +++++++-------- server/lib/federation/outgoing.ts | 31 ++++++++++++++++++++++++++----- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdf25e08..75fb48a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## ??? (Not Released Yet) +### Important fix + +* The livechat plugin broke the federation with Peertube >= 6.1.0. + ### Minor changes and fixes * Fix #378: alert message not visible with dark theme when using external login. diff --git a/server/lib/federation/init.ts b/server/lib/federation/init.ts index 9f78bd58..85bea180 100644 --- a/server/lib/federation/init.ts +++ b/server/lib/federation/init.ts @@ -1,6 +1,6 @@ import type { RegisterServerOptions, VideoObject } from '@peertube/peertube-types' import type { VideoBuildResultContext, RemoteVideoHandlerParams } from './types' -import { videoBuildJSONLD } from './outgoing' +import { videoBuildJSONLD, videoContextBuildJSONLD } from './outgoing' import { readIncomingAPVideo } from './incoming' export async function initFederation (options: RegisterServerOptions): Promise { @@ -15,13 +15,12 @@ export async function initFederation (options: RegisterServerOptions): Promise { - // return videoContectBuildJSONLD(options, jsonld) - // } - // }) + registerHook({ + target: 'filter:activity-pub.activity.context.build.result', + handler: async (jsonld: any) => { + return videoContextBuildJSONLD(options, jsonld) + } + }) registerHook({ target: 'action:activity-pub.remote-video.created', diff --git a/server/lib/federation/outgoing.ts b/server/lib/federation/outgoing.ts index d83a877f..4a4a95d8 100644 --- a/server/lib/federation/outgoing.ts +++ b/server/lib/federation/outgoing.ts @@ -62,9 +62,6 @@ async function videoBuildJSONLD ( logger.debug(`Video uuid=${video.uuid} has not livechat, adding peertubeLiveChat=false.`) // Note: we store also outgoing data. Could help for migration/cleanup scripts, for example. await storeVideoLiveChatInfos(options, video, false) - Object.assign(videoJsonld, { - peertubeLiveChat: false - }) return videoJsonld } @@ -125,6 +122,8 @@ async function videoBuildJSONLD ( // Code beneath this point is for backward compatibility, before v7.2.0. // Since then, the ActivityPub metadata were not standardized. + // Note: plugin version >=7.2.0 still uses these data to get remote server informations + // (not 100% sure if it is needed or not) // For backward compatibility with remote servers, using plugin <=6.3.0, we must provide links: const links: LiveChatJSONLDLink[] = [] @@ -160,6 +159,27 @@ async function videoBuildJSONLD ( return videoJsonld } +async function videoContextBuildJSONLD (_options: RegisterServerOptions, jsonld: any[]): Promise { + // Note: this function is called for all kind of context, not only video. + // We have no parameter to know on which context we currently are. + // See: https://github.com/Chocobozzz/PeerTube/issues/6375 + // But we only want to add some context on videos... + // So, to detect if we are on video, we search for a 'isLiveBroadcast' field in jsonld (this only exists for videos). + + const entry = jsonld.find(e => typeof e === 'object' && ('isLiveBroadcast' in e)) + if (!entry) { + return jsonld + } + + // We are on a video! + return jsonld.concat([{ + ptlc: 'urn:peertube-plugin-livechat', + peertubeLiveChat: { + '@id': 'ptlc:peertubeLiveChat', '@type': '@json' + } + }]) +} + async function serverBuildInfos (options: RegisterServerOptions): Promise { const settings = await options.settingsManager.getSettings([ 'federation-dont-publish-remotely', @@ -192,14 +212,14 @@ async function _serverBuildInfos ( const anonDomain = 'anon.' + prosodyDomain const externalDomain = 'external.' + prosodyDomain - let directs2s + let directs2s: PeertubeXMPPServerInfos['directs2s'] | undefined if (settings['prosody-room-allow-s2s'] && settings['prosody-s2s-port']) { directs2s = { port: (settings['prosody-s2s-port'] as string) ?? '' } } - let websockets2s + let websockets2s: PeertubeXMPPServerInfos['websockets2s'] | undefined if (!settings['federation-dont-publish-remotely']) { const wsS2SUri = getWSS2SUri(options) if (wsS2SUri) { // can be undefined for old Peertube version that dont allow WS for plugins @@ -242,5 +262,6 @@ async function _serverBuildInfos ( export { videoBuildJSONLD, + videoContextBuildJSONLD, serverBuildInfos }