]>
Commit | Line | Data |
---|---|---|
1 | import * as Sequelize from 'sequelize' | |
2 | import { v4 as uuidv4 } from 'uuid' | |
3 | import { VideoChannelCreate } from '../../shared/models' | |
4 | import { VideoModel } from '../models/video/video' | |
5 | import { VideoChannelModel } from '../models/video/video-channel' | |
6 | import { MAccountId, MChannelId } from '../types/models' | |
7 | import { buildActorInstance } from './activitypub/actor' | |
8 | import { getLocalVideoChannelActivityPubUrl } from './activitypub/url' | |
9 | import { federateVideoIfNeeded } from './activitypub/videos' | |
10 | ||
11 | async function createLocalVideoChannel (videoChannelInfo: VideoChannelCreate, account: MAccountId, t: Sequelize.Transaction) { | |
12 | const uuid = uuidv4() | |
13 | const url = getLocalVideoChannelActivityPubUrl(videoChannelInfo.name) | |
14 | const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name, uuid) | |
15 | ||
16 | const actorInstanceCreated = await actorInstance.save({ transaction: t }) | |
17 | ||
18 | const videoChannelData = { | |
19 | name: videoChannelInfo.displayName, | |
20 | description: videoChannelInfo.description, | |
21 | support: videoChannelInfo.support, | |
22 | accountId: account.id, | |
23 | actorId: actorInstanceCreated.id | |
24 | } | |
25 | ||
26 | const videoChannel = new VideoChannelModel(videoChannelData) | |
27 | ||
28 | const options = { transaction: t } | |
29 | const videoChannelCreated = await videoChannel.save(options) | |
30 | ||
31 | videoChannelCreated.Actor = actorInstanceCreated | |
32 | ||
33 | // No need to send this empty video channel to followers | |
34 | return videoChannelCreated | |
35 | } | |
36 | ||
37 | async function federateAllVideosOfChannel (videoChannel: MChannelId) { | |
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 | ||
47 | // --------------------------------------------------------------------------- | |
48 | ||
49 | export { | |
50 | createLocalVideoChannel, | |
51 | federateAllVideosOfChannel | |
52 | } |