1 import { Transaction } from 'sequelize'
2 import { VideoPrivacy } from '../../../shared/models/videos'
3 import { getServerActor } from '../../helpers/utils'
4 import { VideoModel } from '../../models/video/video'
5 import { VideoShareModel } from '../../models/video/video-share'
6 import { sendVideoAnnounceToFollowers } from './send'
7 import { getAnnounceActivityPubUrl } from './url'
9 async function shareVideoByServerAndChannel (video: VideoModel, t: Transaction) {
10 if (video.privacy === VideoPrivacy.PRIVATE) return undefined
12 const serverActor = await getServerActor()
14 const serverShareUrl = getAnnounceActivityPubUrl(video.url, serverActor)
15 const serverSharePromise = VideoShareModel.create({
16 actorId: serverActor.id,
19 }, { transaction: t })
21 const videoChannelShareUrl = getAnnounceActivityPubUrl(video.url, video.VideoChannel.Actor)
22 const videoChannelSharePromise = VideoShareModel.create({
23 actorId: video.VideoChannel.actorId,
25 url: videoChannelShareUrl
26 }, { transaction: t })
28 const [ serverShare, videoChannelShare ] = await Promise.all([
30 videoChannelSharePromise
34 sendVideoAnnounceToFollowers(serverActor, videoChannelShare, video, t),
35 sendVideoAnnounceToFollowers(serverActor, serverShare, video, t)
40 shareVideoByServerAndChannel