]>
Commit | Line | Data |
---|---|---|
72c7248b | 1 | import * as Sequelize from 'sequelize' |
79d5caf9 | 2 | import { VideoChannelCreate } from '../../shared/models' |
7d14d4d2 | 3 | import { VideoModel } from '../models/video/video' |
de94ac86 | 4 | import { VideoChannelModel } from '../models/video/video-channel' |
2cb03dc1 | 5 | import { MAccountId, MChannelId } from '../types/models' |
de94ac86 | 6 | import { getLocalVideoChannelActivityPubUrl } from './activitypub/url' |
7fed6375 | 7 | import { federateVideoIfNeeded } from './activitypub/videos' |
136d7efd | 8 | import { buildActorInstance } from './local-actor' |
72c7248b | 9 | |
2cb03dc1 | 10 | async function createLocalVideoChannel (videoChannelInfo: VideoChannelCreate, account: MAccountId, t: Sequelize.Transaction) { |
de94ac86 | 11 | const url = getLocalVideoChannelActivityPubUrl(videoChannelInfo.name) |
16c016e8 | 12 | const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name) |
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 | ||
453e83ea | 24 | const videoChannel = new VideoChannelModel(videoChannelData) |
e34c85e5 | 25 | |
72c7248b | 26 | const options = { transaction: t } |
2cb03dc1 | 27 | const videoChannelCreated = await videoChannel.save(options) |
eb080476 | 28 | |
50d6de9c | 29 | videoChannelCreated.Actor = actorInstanceCreated |
eb080476 | 30 | |
2cb03dc1 | 31 | // No need to send this empty video channel to followers |
eb080476 C |
32 | return videoChannelCreated |
33 | } | |
34 | ||
453e83ea | 35 | async function federateAllVideosOfChannel (videoChannel: MChannelId) { |
7d14d4d2 C |
36 | const videoIds = await VideoModel.getAllIdsFromChannel(videoChannel) |
37 | ||
38 | for (const videoId of videoIds) { | |
4fae2b1f | 39 | const video = await VideoModel.loadFull(videoId) |
7d14d4d2 C |
40 | |
41 | await federateVideoIfNeeded(video, false) | |
42 | } | |
43 | } | |
44 | ||
72c7248b C |
45 | // --------------------------------------------------------------------------- |
46 | ||
47 | export { | |
1ca9f7c3 | 48 | createLocalVideoChannel, |
7d14d4d2 | 49 | federateAllVideosOfChannel |
72c7248b | 50 | } |