Prosody: the video owner is admin for the room.

This commit is contained in:
John Livingston 2021-05-05 18:00:03 +02:00
parent 5a82f9aa93
commit 27d8ab7fc6
2 changed files with 38 additions and 2 deletions

View File

@ -75,6 +75,7 @@ interface MVideoThumbnail { // FIXME: this interface is not complete.
commentsEnabled: boolean commentsEnabled: boolean
downloadEnabled: boolean downloadEnabled: boolean
state: VideoState state: VideoState
channelId: number
} }
// Keep the order // Keep the order

View File

@ -1,6 +1,6 @@
interface Affiliations { [jid: string]: 'outcast' | 'none' | 'member' | 'admin' | 'owner' } interface Affiliations { [jid: string]: 'outcast' | 'none' | 'member' | 'admin' | 'owner' }
async function getVideoAffiliations (options: RegisterServerOptions, _video: MVideoThumbnail): Promise<Affiliations> { async function getVideoAffiliations (options: RegisterServerOptions, video: MVideoThumbnail): Promise<Affiliations> {
const peertubeHelpers = options.peertubeHelpers const peertubeHelpers = options.peertubeHelpers
// Get all admins and moderators // Get all admins and moderators
const [results] = await peertubeHelpers.database.query( const [results] = await peertubeHelpers.database.query(
@ -23,11 +23,46 @@ async function getVideoAffiliations (options: RegisterServerOptions, _video: MVi
r[jid] = 'owner' r[jid] = 'owner'
} }
// TODO: add a 'admin' affiliation for video owner // Adding an 'admin' affiliation for video owner
// NB: if it fails, we want previous results to be returned...
try {
const userName = await _getVideoOwnerUsername(options, video)
const userJid = userName + '@localhost'
r[userJid] = 'admin'
} catch (error) {
peertubeHelpers.logger.error('Failed to get video owner informations:', error)
}
return r return r
} }
async function _getVideoOwnerUsername (options: RegisterServerOptions, video: MVideoThumbnail): Promise<string> {
// checking type of video.channelId
if (!video.channelId) {
throw new Error('Missing channelId on video')
}
if (!Number.isInteger(video.channelId)) {
throw new Error('Invalid channelId: not an integer')
}
const [results] = await options.peertubeHelpers.database.query(
'SELECT "user"."username"' +
' FROM "videoChannel"' +
' JOIN "account" ON "account"."id" = "videoChannel"."accountId"' +
' JOIN "user" ON "account"."userId" = "user"."id" ' +
' WHERE "videoChannel"."id" = ' + video.channelId.toString()
)
if (!Array.isArray(results)) {
throw new Error('_getVideoOwnerUsername: query result is not an array.')
}
if (!results[0]) {
throw new Error('_getVideoOwnerUsername: no user found')
}
if (!results[0].username) {
throw new Error('_getVideoOwnerUsername: no username in result')
}
return results[0].username as string
}
export { export {
Affiliations, Affiliations,
getVideoAffiliations getVideoAffiliations