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 { audiencify, broadcastToFollowers, getAudience } from './misc'
12 async function sendUpdateVideo (video: VideoModel, t: Transaction) {
13 const byActor = video.VideoChannel.Account.Actor
15 const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString())
16 const videoObject = video.toActivityPubObject()
17 const audience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC)
19 const data = await updateActivityData(url, byActor, videoObject, t, audience)
21 const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
22 actorsInvolved.push(byActor)
24 return broadcastToFollowers(data, byActor, actorsInvolved, t)
27 async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelModel, t: Transaction) {
28 const byActor = accountOrChannel.Actor
30 const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString())
31 const accountOrChannelObject = accountOrChannel.toActivityPubObject()
32 const audience = await getAudience(byActor, t)
33 const data = await updateActivityData(url, byActor, accountOrChannelObject, t, audience)
35 let actorsInvolved: ActorModel[]
36 if (accountOrChannel instanceof AccountModel) {
37 // Actors that shared my videos are involved too
38 actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t)
40 // Actors that shared videos of my channel are involved too
41 actorsInvolved = await VideoShareModel.loadActorsByVideoChannel(accountOrChannel.id, t)
44 actorsInvolved.push(byActor)
46 return broadcastToFollowers(data, byActor, actorsInvolved, t)
49 // ---------------------------------------------------------------------------
56 // ---------------------------------------------------------------------------
58 async function updateActivityData (
63 audience?: ActivityAudience
64 ): Promise<ActivityUpdate> {
66 audience = await getAudience(byActor, t)
73 object: audiencify(object, audience)