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