]>
Commit | Line | Data |
---|---|---|
72c7248b | 1 | import * as Sequelize from 'sequelize' |
50d6de9c | 2 | import * as uuidv4 from 'uuid/v4' |
79d5caf9 | 3 | import { VideoChannelCreate } from '../../shared/models' |
3fd3ab2d C |
4 | import { AccountModel } from '../models/account/account' |
5 | import { VideoChannelModel } from '../models/video/video-channel' | |
7d14d4d2 C |
6 | import { buildActorInstance, federateVideoIfNeeded, getVideoChannelActivityPubUrl } from './activitypub' |
7 | import { VideoModel } from '../models/video/video' | |
72c7248b | 8 | |
3fd3ab2d | 9 | async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountModel, t: Sequelize.Transaction) { |
50d6de9c | 10 | const uuid = uuidv4() |
8a19bee1 C |
11 | const url = getVideoChannelActivityPubUrl(videoChannelInfo.name) |
12 | const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name, uuid) | |
50d6de9c C |
13 | |
14 | const actorInstanceCreated = await actorInstance.save({ transaction: t }) | |
15 | ||
72c7248b | 16 | const videoChannelData = { |
08c1efbe | 17 | name: videoChannelInfo.displayName, |
72c7248b | 18 | description: videoChannelInfo.description, |
2422c46b | 19 | support: videoChannelInfo.support, |
50d6de9c C |
20 | accountId: account.id, |
21 | actorId: actorInstanceCreated.id | |
72c7248b C |
22 | } |
23 | ||
3fd3ab2d | 24 | const videoChannel = VideoChannelModel.build(videoChannelData) |
e34c85e5 | 25 | |
72c7248b | 26 | const options = { transaction: t } |
eb080476 C |
27 | const videoChannelCreated = await videoChannel.save(options) |
28 | ||
50d6de9c | 29 | // Do not forget to add Account/Actor information to the created video channel |
e4f97bab | 30 | videoChannelCreated.Account = account |
50d6de9c | 31 | videoChannelCreated.Actor = actorInstanceCreated |
eb080476 | 32 | |
47e0652b | 33 | // No need to seed this empty video channel to followers |
eb080476 C |
34 | return videoChannelCreated |
35 | } | |
36 | ||
7d14d4d2 C |
37 | async function federateAllVideosOfChannel (videoChannel: VideoChannelModel) { |
38 | const videoIds = await VideoModel.getAllIdsFromChannel(videoChannel) | |
39 | ||
40 | for (const videoId of videoIds) { | |
41 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId) | |
42 | ||
43 | await federateVideoIfNeeded(video, false) | |
44 | } | |
45 | } | |
46 | ||
72c7248b C |
47 | // --------------------------------------------------------------------------- |
48 | ||
49 | export { | |
7d14d4d2 C |
50 | createVideoChannel, |
51 | federateAllVideosOfChannel | |
72c7248b | 52 | } |