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