]>
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' |
7d14d4d2 | 4 | import { VideoModel } from '../models/video/video' |
de94ac86 | 5 | import { VideoChannelModel } from '../models/video/video-channel' |
2cb03dc1 | 6 | import { MAccountId, MChannelId } from '../types/models' |
de94ac86 C |
7 | import { buildActorInstance } from './activitypub/actor' |
8 | import { getLocalVideoChannelActivityPubUrl } from './activitypub/url' | |
7fed6375 | 9 | import { federateVideoIfNeeded } from './activitypub/videos' |
72c7248b | 10 | |
2cb03dc1 | 11 | async function createLocalVideoChannel (videoChannelInfo: VideoChannelCreate, account: MAccountId, t: Sequelize.Transaction) { |
50d6de9c | 12 | const uuid = uuidv4() |
de94ac86 | 13 | const url = getLocalVideoChannelActivityPubUrl(videoChannelInfo.name) |
8a19bee1 | 14 | const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name, uuid) |
50d6de9c C |
15 | |
16 | const actorInstanceCreated = await actorInstance.save({ transaction: t }) | |
17 | ||
72c7248b | 18 | const videoChannelData = { |
08c1efbe | 19 | name: videoChannelInfo.displayName, |
72c7248b | 20 | description: videoChannelInfo.description, |
2422c46b | 21 | support: videoChannelInfo.support, |
50d6de9c C |
22 | accountId: account.id, |
23 | actorId: actorInstanceCreated.id | |
72c7248b C |
24 | } |
25 | ||
453e83ea | 26 | const videoChannel = new VideoChannelModel(videoChannelData) |
e34c85e5 | 27 | |
72c7248b | 28 | const options = { transaction: t } |
2cb03dc1 | 29 | const videoChannelCreated = await videoChannel.save(options) |
eb080476 | 30 | |
50d6de9c | 31 | videoChannelCreated.Actor = actorInstanceCreated |
eb080476 | 32 | |
2cb03dc1 | 33 | // No need to send this empty video channel to followers |
eb080476 C |
34 | return videoChannelCreated |
35 | } | |
36 | ||
453e83ea | 37 | async function federateAllVideosOfChannel (videoChannel: MChannelId) { |
7d14d4d2 C |
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 { | |
1ca9f7c3 | 50 | createLocalVideoChannel, |
7d14d4d2 | 51 | federateAllVideosOfChannel |
72c7248b | 52 | } |