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.
Implements #400.
This commit is contained in:
John Livingston 2024-06-14 17:56:22 +02:00
parent ae2d45b007
commit 9e8e2a2572
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
2 changed files with 15 additions and 4 deletions

View File

@ -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. * #416: Deregister prosodyctl interval callback when spawn.stdin disappears.
* #423: Merging video-watch scope into common scope. * #423: Merging video-watch scope into common scope.
* Rewriting the share chat dialog with more modern code. * 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 ## 10.0.2

View File

@ -13,15 +13,26 @@ async function initCustomFields (options: RegisterServerOptions): Promise<void>
registerHook({ registerHook({
target: 'action:api.live-video.created', 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 } 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. // 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 // 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') const setting = await options.settingsManager.getSetting('chat-per-live-video')
if (setting !== true) { return } if (setting !== true) { return }
logger.info( 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) await storageManager.storeData(`livechat-active-${video.id.toString()}`, true)
} }