1 import { Transaction } from 'sequelize'
2 import { ActivityAudience, ActivityUpdate } from '../../../../shared/models/activitypub'
3 import { VideoPrivacy } from '../../../../shared/models/videos'
4 import { AccountModel } from '../../../models/account/account'
5 import { ActorModel } from '../../../models/activitypub/actor'
6 import { VideoModel } from '../../../models/video/video'
7 import { VideoChannelModel } from '../../../models/video/video-channel'
8 import { VideoShareModel } from '../../../models/video/video-share'
9 import { getUpdateActivityPubUrl } from '../url'
10 import { broadcastToFollowers } from './utils'
11 import { audiencify, getAudience } from '../audience'
12 import { logger } from '../../../helpers/logger'
14 async function sendUpdateVideo (video: VideoModel, t: Transaction) {
15 logger.info('Creating job to update video %s.', video.url)
17 const byActor = video.VideoChannel.Account.Actor
19 const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString())
20 const videoObject = video.toActivityPubObject()
21 const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC)
23 const data = updateActivityData(url, byActor, videoObject, audience)
25 const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
26 actorsInvolved.push(byActor)
28 return broadcastToFollowers(data, byActor, actorsInvolved, t)
31 async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelModel, t: Transaction) {
32 const byActor = accountOrChannel.Actor
34 logger.info('Creating job to update actor %s.', byActor.url)
36 const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString())
37 const accountOrChannelObject = accountOrChannel.toActivityPubObject()
38 const audience = getAudience(byActor)
39 const data = updateActivityData(url, byActor, accountOrChannelObject, audience)
41 let actorsInvolved: ActorModel[]
42 if (accountOrChannel instanceof AccountModel) {
43 // Actors that shared my videos are involved too
44 actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t)
46 // Actors that shared videos of my channel are involved too
47 actorsInvolved = await VideoShareModel.loadActorsByVideoChannel(accountOrChannel.id, t)
50 actorsInvolved.push(byActor)
52 return broadcastToFollowers(data, byActor, actorsInvolved, t)
55 // ---------------------------------------------------------------------------
62 // ---------------------------------------------------------------------------
64 function updateActivityData (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityUpdate {
65 if (!audience) audience = getAudience(byActor)
69 type: 'Update' as 'Update',
72 object: audiencify(object, audience