From ae2d45b0077f6d5c42df170b40eab906915ccde5 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Tue, 11 Jun 2024 10:41:12 +0200 Subject: [PATCH] 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. Fix #400. --- CHANGELOG.md | 1 + server/lib/custom-fields.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ce2626c..2b85541c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +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. ## 10.0.2 diff --git a/server/lib/custom-fields.ts b/server/lib/custom-fields.ts index ca0e8f10..d51fe752 100644 --- a/server/lib/custom-fields.ts +++ b/server/lib/custom-fields.ts @@ -11,6 +11,22 @@ async function initCustomFields (options: RegisterServerOptions): Promise const storageManager = options.storageManager const logger = options.peertubeHelpers.logger + registerHook({ + target: 'action:api.live-video.created', + handler: async ({ video }: { video: Video | undefined }) => { + if (!video?.id) { return } + // When creating a new live, if the chat is an option 'per video', we enable the chat by default. + // 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 + 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()}.` + ) + await storageManager.storeData(`livechat-active-${video.id.toString()}`, true) + } + }) + registerHook({ target: 'action:api.video.updated', handler: async (params: any) => {