Fix player play exception on chromium
[oweals/peertube.git] / server / lib / activitypub / send / send-update.ts
1 import { Transaction } from 'sequelize'
2 import { ActivityAudience, ActivityUpdate } from '../../../../shared/models/activitypub'
3 import { VideoPrivacy } from '../../../../shared/models/videos'
4 import { ActorModel } from '../../../models/activitypub/actor'
5 import { VideoModel } from '../../../models/video/video'
6 import { VideoShareModel } from '../../../models/video/video-share'
7 import { getUpdateActivityPubUrl } from '../url'
8 import { audiencify, broadcastToFollowers, getAudience } from './misc'
9
10 async function sendUpdateVideo (video: VideoModel, t: Transaction) {
11   const byActor = video.VideoChannel.Account.Actor
12
13   const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString())
14   const videoObject = video.toActivityPubObject()
15   const audience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC)
16
17   const data = await updateActivityData(url, byActor, videoObject, t, audience)
18
19   const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
20   actorsInvolved.push(byActor)
21
22   return broadcastToFollowers(data, byActor, actorsInvolved, t)
23 }
24
25 // ---------------------------------------------------------------------------
26
27 export {
28   sendUpdateVideo
29 }
30
31 // ---------------------------------------------------------------------------
32
33 async function updateActivityData (
34   url: string,
35   byActor: ActorModel,
36   object: any,
37   t: Transaction,
38   audience?: ActivityAudience
39 ): Promise<ActivityUpdate> {
40   if (!audience) {
41     audience = await getAudience(byActor, t)
42   }
43
44   return audiencify({
45     type: 'Update',
46     id: url,
47     actor: byActor.url,
48     object: audiencify(object, audience)
49   }, audience)
50 }