]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/lib/activitypub/send/send-update.ts
Bumped to version v1.0.0-beta.13
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-update.ts
... / ...
CommitLineData
1import { Transaction } from 'sequelize'
2import { ActivityAudience, ActivityUpdate } from '../../../../shared/models/activitypub'
3import { VideoPrivacy } from '../../../../shared/models/videos'
4import { AccountModel } from '../../../models/account/account'
5import { ActorModel } from '../../../models/activitypub/actor'
6import { VideoModel } from '../../../models/video/video'
7import { VideoChannelModel } from '../../../models/video/video-channel'
8import { VideoShareModel } from '../../../models/video/video-share'
9import { getUpdateActivityPubUrl } from '../url'
10import { broadcastToFollowers } from './utils'
11import { audiencify, getAudience } from '../audience'
12import { logger } from '../../../helpers/logger'
13import { videoFeedsValidator } from '../../../middlewares/validators'
14import { VideoCaptionModel } from '../../../models/video/video-caption'
15
16async function sendUpdateVideo (video: VideoModel, t: Transaction, overrodeByActor?: ActorModel) {
17 logger.info('Creating job to update video %s.', video.url)
18
19 const byActor = overrodeByActor ? overrodeByActor : video.VideoChannel.Account.Actor
20
21 const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString())
22
23 // Needed to build the AP object
24 if (!video.VideoCaptions) video.VideoCaptions = await video.$get('VideoCaptions') as VideoCaptionModel[]
25
26 const videoObject = video.toActivityPubObject()
27 const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC)
28
29 const data = updateActivityData(url, byActor, videoObject, audience)
30
31 const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
32 actorsInvolved.push(byActor)
33
34 return broadcastToFollowers(data, byActor, actorsInvolved, t)
35}
36
37async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelModel, t: Transaction) {
38 const byActor = accountOrChannel.Actor
39
40 logger.info('Creating job to update actor %s.', byActor.url)
41
42 const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString())
43 const accountOrChannelObject = accountOrChannel.toActivityPubObject()
44 const audience = getAudience(byActor)
45 const data = updateActivityData(url, byActor, accountOrChannelObject, audience)
46
47 let actorsInvolved: ActorModel[]
48 if (accountOrChannel instanceof AccountModel) {
49 // Actors that shared my videos are involved too
50 actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t)
51 } else {
52 // Actors that shared videos of my channel are involved too
53 actorsInvolved = await VideoShareModel.loadActorsByVideoChannel(accountOrChannel.id, t)
54 }
55
56 actorsInvolved.push(byActor)
57
58 return broadcastToFollowers(data, byActor, actorsInvolved, t)
59}
60
61// ---------------------------------------------------------------------------
62
63export {
64 sendUpdateActor,
65 sendUpdateVideo
66}
67
68// ---------------------------------------------------------------------------
69
70function updateActivityData (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityUpdate {
71 if (!audience) audience = getAudience(byActor)
72
73 return audiencify(
74 {
75 type: 'Update' as 'Update',
76 id: url,
77 actor: byActor.url,
78 object: audiencify(object, audience
79 )
80 },
81 audience
82 )
83}