1 import * as Sequelize from 'sequelize'
2 import { v4 as uuidv4 } from 'uuid'
3 import { VideoChannelCreate } from '../../shared/models'
4 import { VideoModel } from '../models/video/video'
5 import { VideoChannelModel } from '../models/video/video-channel'
6 import { MAccountId, MChannelId } from '../types/models'
7 import { buildActorInstance } from './activitypub/actor'
8 import { getLocalVideoChannelActivityPubUrl } from './activitypub/url'
9 import { federateVideoIfNeeded } from './activitypub/videos'
11 async function createLocalVideoChannel (videoChannelInfo: VideoChannelCreate, account: MAccountId, t: Sequelize.Transaction) {
13 const url = getLocalVideoChannelActivityPubUrl(videoChannelInfo.name)
14 const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name, uuid)
16 const actorInstanceCreated = await actorInstance.save({ transaction: t })
18 const videoChannelData = {
19 name: videoChannelInfo.displayName,
20 description: videoChannelInfo.description,
21 support: videoChannelInfo.support,
22 accountId: account.id,
23 actorId: actorInstanceCreated.id
26 const videoChannel = new VideoChannelModel(videoChannelData)
28 const options = { transaction: t }
29 const videoChannelCreated = await videoChannel.save(options)
31 videoChannelCreated.Actor = actorInstanceCreated
33 // No need to send this empty video channel to followers
34 return videoChannelCreated
37 async function federateAllVideosOfChannel (videoChannel: MChannelId) {
38 const videoIds = await VideoModel.getAllIdsFromChannel(videoChannel)
40 for (const videoId of videoIds) {
41 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId)
43 await federateVideoIfNeeded(video, false)
47 // ---------------------------------------------------------------------------
50 createLocalVideoChannel,
51 federateAllVideosOfChannel