]>
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 | 4 | import { VideoChannelModel } from '../models/video/video-channel' |
7d14d4d2 C |
5 | import { buildActorInstance, federateVideoIfNeeded, getVideoChannelActivityPubUrl } from './activitypub' |
6 | import { VideoModel } from '../models/video/video' | |
1ca9f7c3 | 7 | import { MAccountId, MChannelDefault, MChannelId } from '../typings/models' |
72c7248b | 8 | |
1ca9f7c3 | 9 | type CustomVideoChannelModelAccount <T extends MAccountId> = MChannelDefault & |
453e83ea C |
10 | { Account?: T } |
11 | ||
1ca9f7c3 | 12 | async function createLocalVideoChannel <T extends MAccountId> ( |
453e83ea C |
13 | videoChannelInfo: VideoChannelCreate, |
14 | account: T, | |
15 | t: Sequelize.Transaction | |
16 | ): Promise<CustomVideoChannelModelAccount<T>> { | |
50d6de9c | 17 | const uuid = uuidv4() |
8a19bee1 C |
18 | const url = getVideoChannelActivityPubUrl(videoChannelInfo.name) |
19 | const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name, uuid) | |
50d6de9c C |
20 | |
21 | const actorInstanceCreated = await actorInstance.save({ transaction: t }) | |
22 | ||
72c7248b | 23 | const videoChannelData = { |
08c1efbe | 24 | name: videoChannelInfo.displayName, |
72c7248b | 25 | description: videoChannelInfo.description, |
2422c46b | 26 | support: videoChannelInfo.support, |
50d6de9c C |
27 | accountId: account.id, |
28 | actorId: actorInstanceCreated.id | |
72c7248b C |
29 | } |
30 | ||
453e83ea | 31 | const videoChannel = new VideoChannelModel(videoChannelData) |
e34c85e5 | 32 | |
72c7248b | 33 | const options = { transaction: t } |
1ca9f7c3 | 34 | const videoChannelCreated: CustomVideoChannelModelAccount<T> = await videoChannel.save(options) as MChannelDefault |
eb080476 | 35 | |
50d6de9c | 36 | // Do not forget to add Account/Actor information to the created video channel |
e4f97bab | 37 | videoChannelCreated.Account = account |
50d6de9c | 38 | videoChannelCreated.Actor = actorInstanceCreated |
eb080476 | 39 | |
47e0652b | 40 | // No need to seed this empty video channel to followers |
eb080476 C |
41 | return videoChannelCreated |
42 | } | |
43 | ||
453e83ea | 44 | async function federateAllVideosOfChannel (videoChannel: MChannelId) { |
7d14d4d2 C |
45 | const videoIds = await VideoModel.getAllIdsFromChannel(videoChannel) |
46 | ||
47 | for (const videoId of videoIds) { | |
48 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId) | |
49 | ||
50 | await federateVideoIfNeeded(video, false) | |
51 | } | |
52 | } | |
53 | ||
72c7248b C |
54 | // --------------------------------------------------------------------------- |
55 | ||
56 | export { | |
1ca9f7c3 | 57 | createLocalVideoChannel, |
7d14d4d2 | 58 | federateAllVideosOfChannel |
72c7248b | 59 | } |