2017-10-24 13:41:09 -04:00
|
|
|
import * as Sequelize from 'sequelize'
|
2017-11-17 09:52:26 -05:00
|
|
|
import { VideoChannelCreate } from '../../shared/models'
|
2019-05-31 10:30:11 -04:00
|
|
|
import { VideoModel } from '../models/video/video'
|
2020-11-20 05:21:08 -05:00
|
|
|
import { VideoChannelModel } from '../models/video/video-channel'
|
2021-04-06 11:01:35 -04:00
|
|
|
import { MAccountId, MChannelId } from '../types/models'
|
2020-11-20 05:21:08 -05:00
|
|
|
import { buildActorInstance } from './activitypub/actor'
|
|
|
|
import { getLocalVideoChannelActivityPubUrl } from './activitypub/url'
|
2020-04-22 10:07:04 -04:00
|
|
|
import { federateVideoIfNeeded } from './activitypub/videos'
|
2017-10-24 13:41:09 -04:00
|
|
|
|
2021-04-06 11:01:35 -04:00
|
|
|
async function createLocalVideoChannel (videoChannelInfo: VideoChannelCreate, account: MAccountId, t: Sequelize.Transaction) {
|
2020-11-20 05:21:08 -05:00
|
|
|
const url = getLocalVideoChannelActivityPubUrl(videoChannelInfo.name)
|
2021-05-12 08:09:04 -04:00
|
|
|
const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name)
|
2017-12-14 11:38:41 -05:00
|
|
|
|
|
|
|
const actorInstanceCreated = await actorInstance.save({ transaction: t })
|
|
|
|
|
2017-10-24 13:41:09 -04:00
|
|
|
const videoChannelData = {
|
2018-04-26 10:11:38 -04:00
|
|
|
name: videoChannelInfo.displayName,
|
2017-10-24 13:41:09 -04:00
|
|
|
description: videoChannelInfo.description,
|
2018-02-15 08:46:26 -05:00
|
|
|
support: videoChannelInfo.support,
|
2017-12-14 11:38:41 -05:00
|
|
|
accountId: account.id,
|
|
|
|
actorId: actorInstanceCreated.id
|
2017-10-24 13:41:09 -04:00
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
const videoChannel = new VideoChannelModel(videoChannelData)
|
2017-11-14 04:57:56 -05:00
|
|
|
|
2017-10-24 13:41:09 -04:00
|
|
|
const options = { transaction: t }
|
2021-04-06 11:01:35 -04:00
|
|
|
const videoChannelCreated = await videoChannel.save(options)
|
2017-10-25 05:55:06 -04:00
|
|
|
|
2017-12-14 11:38:41 -05:00
|
|
|
videoChannelCreated.Actor = actorInstanceCreated
|
2017-10-25 05:55:06 -04:00
|
|
|
|
2021-04-06 11:01:35 -04:00
|
|
|
// No need to send this empty video channel to followers
|
2017-10-25 05:55:06 -04:00
|
|
|
return videoChannelCreated
|
|
|
|
}
|
|
|
|
|
2019-08-15 05:53:26 -04:00
|
|
|
async function federateAllVideosOfChannel (videoChannel: MChannelId) {
|
2019-05-31 10:30:11 -04:00
|
|
|
const videoIds = await VideoModel.getAllIdsFromChannel(videoChannel)
|
|
|
|
|
|
|
|
for (const videoId of videoIds) {
|
|
|
|
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId)
|
|
|
|
|
|
|
|
await federateVideoIfNeeded(video, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-24 13:41:09 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2019-08-20 13:05:31 -04:00
|
|
|
createLocalVideoChannel,
|
2019-05-31 10:30:11 -04:00
|
|
|
federateAllVideosOfChannel
|
2017-10-24 13:41:09 -04:00
|
|
|
}
|