]>
Commit | Line | Data |
---|---|---|
1 | import * as Sequelize from 'sequelize' | |
2 | import * as uuidv4 from 'uuid/v4' | |
3 | import { VideoChannelCreate } from '../../shared/models' | |
4 | import { AccountModel } from '../models/account/account' | |
5 | import { VideoChannelModel } from '../models/video/video-channel' | |
6 | import { buildActorInstance, getVideoChannelActivityPubUrl } from './activitypub' | |
7 | ||
8 | async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountModel, t: Sequelize.Transaction) { | |
9 | const uuid = uuidv4() | |
10 | const url = getVideoChannelActivityPubUrl(videoChannelInfo.name) | |
11 | const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name, uuid) | |
12 | ||
13 | const actorInstanceCreated = await actorInstance.save({ transaction: t }) | |
14 | ||
15 | const videoChannelData = { | |
16 | name: videoChannelInfo.displayName, | |
17 | description: videoChannelInfo.description, | |
18 | support: videoChannelInfo.support, | |
19 | accountId: account.id, | |
20 | actorId: actorInstanceCreated.id | |
21 | } | |
22 | ||
23 | const videoChannel = VideoChannelModel.build(videoChannelData) | |
24 | ||
25 | const options = { transaction: t } | |
26 | const videoChannelCreated = await videoChannel.save(options) | |
27 | ||
28 | // Do not forget to add Account/Actor information to the created video channel | |
29 | videoChannelCreated.Account = account | |
30 | videoChannelCreated.Actor = actorInstanceCreated | |
31 | ||
32 | // No need to seed this empty video channel to followers | |
33 | return videoChannelCreated | |
34 | } | |
35 | ||
36 | // --------------------------------------------------------------------------- | |
37 | ||
38 | export { | |
39 | createVideoChannel | |
40 | } |