diff options
Diffstat (limited to 'server/lib/activitypub/send/send-update.ts')
-rw-r--r-- | server/lib/activitypub/send/send-update.ts | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/server/lib/activitypub/send/send-update.ts b/server/lib/activitypub/send/send-update.ts index 6f1d80898..605473338 100644 --- a/server/lib/activitypub/send/send-update.ts +++ b/server/lib/activitypub/send/send-update.ts | |||
@@ -7,11 +7,11 @@ import { VideoModel } from '../../../models/video/video' | |||
7 | import { VideoChannelModel } from '../../../models/video/video-channel' | 7 | import { VideoChannelModel } from '../../../models/video/video-channel' |
8 | import { VideoShareModel } from '../../../models/video/video-share' | 8 | import { VideoShareModel } from '../../../models/video/video-share' |
9 | import { getUpdateActivityPubUrl } from '../url' | 9 | import { getUpdateActivityPubUrl } from '../url' |
10 | import { broadcastToFollowers } from './utils' | 10 | import { broadcastToFollowers, unicastTo } from './utils' |
11 | import { audiencify, getAudience } from '../audience' | 11 | import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from '../audience' |
12 | import { logger } from '../../../helpers/logger' | 12 | import { logger } from '../../../helpers/logger' |
13 | import { videoFeedsValidator } from '../../../middlewares/validators' | ||
14 | import { VideoCaptionModel } from '../../../models/video/video-caption' | 13 | import { VideoCaptionModel } from '../../../models/video/video-caption' |
14 | import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' | ||
15 | 15 | ||
16 | async function sendUpdateVideo (video: VideoModel, t: Transaction, overrodeByActor?: ActorModel) { | 16 | async function sendUpdateVideo (video: VideoModel, t: Transaction, overrodeByActor?: ActorModel) { |
17 | logger.info('Creating job to update video %s.', video.url) | 17 | logger.info('Creating job to update video %s.', video.url) |
@@ -26,12 +26,12 @@ async function sendUpdateVideo (video: VideoModel, t: Transaction, overrodeByAct | |||
26 | const videoObject = video.toActivityPubObject() | 26 | const videoObject = video.toActivityPubObject() |
27 | const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC) | 27 | const audience = getAudience(byActor, video.privacy === VideoPrivacy.PUBLIC) |
28 | 28 | ||
29 | const data = updateActivityData(url, byActor, videoObject, audience) | 29 | const updateActivity = buildUpdateActivity(url, byActor, videoObject, audience) |
30 | 30 | ||
31 | const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t) | 31 | const actorsInvolved = await getActorsInvolvedInVideo(video, t) |
32 | actorsInvolved.push(byActor) | 32 | if (overrodeByActor) actorsInvolved.push(overrodeByActor) |
33 | 33 | ||
34 | return broadcastToFollowers(data, byActor, actorsInvolved, t) | 34 | return broadcastToFollowers(updateActivity, byActor, actorsInvolved, t) |
35 | } | 35 | } |
36 | 36 | ||
37 | async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelModel, t: Transaction) { | 37 | async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelModel, t: Transaction) { |
@@ -42,7 +42,7 @@ async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelMod | |||
42 | const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString()) | 42 | const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString()) |
43 | const accountOrChannelObject = accountOrChannel.toActivityPubObject() | 43 | const accountOrChannelObject = accountOrChannel.toActivityPubObject() |
44 | const audience = getAudience(byActor) | 44 | const audience = getAudience(byActor) |
45 | const data = updateActivityData(url, byActor, accountOrChannelObject, audience) | 45 | const updateActivity = buildUpdateActivity(url, byActor, accountOrChannelObject, audience) |
46 | 46 | ||
47 | let actorsInvolved: ActorModel[] | 47 | let actorsInvolved: ActorModel[] |
48 | if (accountOrChannel instanceof AccountModel) { | 48 | if (accountOrChannel instanceof AccountModel) { |
@@ -55,19 +55,35 @@ async function sendUpdateActor (accountOrChannel: AccountModel | VideoChannelMod | |||
55 | 55 | ||
56 | actorsInvolved.push(byActor) | 56 | actorsInvolved.push(byActor) |
57 | 57 | ||
58 | return broadcastToFollowers(data, byActor, actorsInvolved, t) | 58 | return broadcastToFollowers(updateActivity, byActor, actorsInvolved, t) |
59 | } | ||
60 | |||
61 | async function sendUpdateCacheFile (byActor: ActorModel, redundancyModel: VideoRedundancyModel) { | ||
62 | logger.info('Creating job to update cache file %s.', redundancyModel.url) | ||
63 | |||
64 | const url = getUpdateActivityPubUrl(redundancyModel.url, redundancyModel.updatedAt.toISOString()) | ||
65 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(redundancyModel.VideoFile.Video.id) | ||
66 | |||
67 | const redundancyObject = redundancyModel.toActivityPubObject() | ||
68 | |||
69 | const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, undefined) | ||
70 | const audience = getObjectFollowersAudience(accountsInvolvedInVideo) | ||
71 | |||
72 | const updateActivity = buildUpdateActivity(url, byActor, redundancyObject, audience) | ||
73 | return unicastTo(updateActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) | ||
59 | } | 74 | } |
60 | 75 | ||
61 | // --------------------------------------------------------------------------- | 76 | // --------------------------------------------------------------------------- |
62 | 77 | ||
63 | export { | 78 | export { |
64 | sendUpdateActor, | 79 | sendUpdateActor, |
65 | sendUpdateVideo | 80 | sendUpdateVideo, |
81 | sendUpdateCacheFile | ||
66 | } | 82 | } |
67 | 83 | ||
68 | // --------------------------------------------------------------------------- | 84 | // --------------------------------------------------------------------------- |
69 | 85 | ||
70 | function updateActivityData (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityUpdate { | 86 | function buildUpdateActivity (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityUpdate { |
71 | if (!audience) audience = getAudience(byActor) | 87 | if (!audience) audience = getAudience(byActor) |
72 | 88 | ||
73 | return audiencify( | 89 | return audiencify( |