diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b85541c..829b6fcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ TODO: tag conversejs livechat branch, and replace commit ID in build-converse.js * #416: Deregister prosodyctl interval callback when spawn.stdin disappears. * #423: Merging video-watch scope into common scope. * Rewriting the share chat dialog with more modern code. -* #400: Enable the chat by default when a live is created. So that lives created by the Android Peertube Live app will have chat by default. +* #400: Reading livechat-active parameter on live creation API endpoint. So that the Android Peertube Live app can pass the parameter withing the first (and only) API call. ## 10.0.2 diff --git a/server/lib/custom-fields.ts b/server/lib/custom-fields.ts index d51fe752..53cf541a 100644 --- a/server/lib/custom-fields.ts +++ b/server/lib/custom-fields.ts @@ -13,15 +13,26 @@ async function initCustomFields (options: RegisterServerOptions): Promise registerHook({ target: 'action:api.live-video.created', - handler: async ({ video }: { video: Video | undefined }) => { + handler: async ({ video, req }: { video: Video | undefined, req: any }) => { if (!video?.id) { return } - // When creating a new live, if the chat is an option 'per video', we enable the chat by default. + // When creating a new live, if 'chat-per-live-video' is true, + // we must read req.body.pluginData['livechat-active'] (as for action:api.video.updated). // This is done for the Peertube live Android app, which does not update the video after creation. // See: https://github.com/JohnXLivingston/peertube-plugin-livechat/issues/400 + + // Note: following code is a little bit verbose, to be sure it can't fail, even with old Peertube versions. + if (!req || (typeof req !== 'object') || !('body' in req)) { return } + if (!req.body || (typeof req.body !== 'object') || !('pluginData' in req.body)) { return } + const pluginData = req.body?.pluginData + if (!pluginData || (typeof pluginData !== 'object') || !('livechat-active' in pluginData)) { return } + if (pluginData['livechat-active'] !== true) { return } + const setting = await options.settingsManager.getSetting('chat-per-live-video') if (setting !== true) { return } + logger.info( - `New live created, enabling chat by default by setting livechat-active=true for video ${video.id.toString()}.` + 'New live created, livechat-active parameter given, ' + + `enabling chat by default by setting livechat-active=true for video ${video.id.toString()}.` ) await storageManager.storeData(`livechat-active-${video.id.toString()}`, true) }