diff options
Diffstat (limited to 'server/lib/activitypub/send/utils.ts')
-rw-r--r-- | server/lib/activitypub/send/utils.ts | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/server/lib/activitypub/send/utils.ts b/server/lib/activitypub/send/utils.ts index 69706e620..1faae1d84 100644 --- a/server/lib/activitypub/send/utils.ts +++ b/server/lib/activitypub/send/utils.ts | |||
@@ -7,6 +7,7 @@ import { JobQueue } from '../../job-queue' | |||
7 | import { VideoModel } from '../../../models/video/video' | 7 | import { VideoModel } from '../../../models/video/video' |
8 | import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience' | 8 | import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience' |
9 | import { getServerActor } from '../../../helpers/utils' | 9 | import { getServerActor } from '../../../helpers/utils' |
10 | import { afterCommitIfTransaction } from '../../../helpers/database-utils' | ||
10 | 11 | ||
11 | async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: { | 12 | async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: { |
12 | byActor: ActorModel, | 13 | byActor: ActorModel, |
@@ -20,7 +21,9 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud | |||
20 | const audience = getRemoteVideoAudience(options.video, actorsInvolvedInVideo) | 21 | const audience = getRemoteVideoAudience(options.video, actorsInvolvedInVideo) |
21 | const activity = activityBuilder(audience) | 22 | const activity = activityBuilder(audience) |
22 | 23 | ||
23 | return unicastTo(activity, options.byActor, options.video.VideoChannel.Account.Actor.sharedInboxUrl) | 24 | return afterCommitIfTransaction(options.transaction, () => { |
25 | return unicastTo(activity, options.byActor, options.video.VideoChannel.Account.Actor.sharedInboxUrl) | ||
26 | }) | ||
24 | } | 27 | } |
25 | 28 | ||
26 | // Send to followers | 29 | // Send to followers |
@@ -28,6 +31,7 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud | |||
28 | const activity = activityBuilder(audience) | 31 | const activity = activityBuilder(audience) |
29 | 32 | ||
30 | const actorsException = [ options.byActor ] | 33 | const actorsException = [ options.byActor ] |
34 | |||
31 | return broadcastToFollowers(activity, options.byActor, actorsInvolvedInVideo, options.transaction, actorsException) | 35 | return broadcastToFollowers(activity, options.byActor, actorsInvolvedInVideo, options.transaction, actorsException) |
32 | } | 36 | } |
33 | 37 | ||
@@ -76,7 +80,7 @@ async function forwardActivity ( | |||
76 | uris, | 80 | uris, |
77 | body: activity | 81 | body: activity |
78 | } | 82 | } |
79 | return JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload }) | 83 | return afterCommitIfTransaction(t, () => JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload })) |
80 | } | 84 | } |
81 | 85 | ||
82 | async function broadcastToFollowers ( | 86 | async function broadcastToFollowers ( |
@@ -87,20 +91,22 @@ async function broadcastToFollowers ( | |||
87 | actorsException: ActorModel[] = [] | 91 | actorsException: ActorModel[] = [] |
88 | ) { | 92 | ) { |
89 | const uris = await computeFollowerUris(toFollowersOf, actorsException, t) | 93 | const uris = await computeFollowerUris(toFollowersOf, actorsException, t) |
90 | return broadcastTo(uris, data, byActor) | 94 | |
95 | return afterCommitIfTransaction(t, () => broadcastTo(uris, data, byActor)) | ||
91 | } | 96 | } |
92 | 97 | ||
93 | async function broadcastToActors ( | 98 | async function broadcastToActors ( |
94 | data: any, | 99 | data: any, |
95 | byActor: ActorModel, | 100 | byActor: ActorModel, |
96 | toActors: ActorModel[], | 101 | toActors: ActorModel[], |
102 | t?: Transaction, | ||
97 | actorsException: ActorModel[] = [] | 103 | actorsException: ActorModel[] = [] |
98 | ) { | 104 | ) { |
99 | const uris = await computeUris(toActors, actorsException) | 105 | const uris = await computeUris(toActors, actorsException) |
100 | return broadcastTo(uris, data, byActor) | 106 | return afterCommitIfTransaction(t, () => broadcastTo(uris, data, byActor)) |
101 | } | 107 | } |
102 | 108 | ||
103 | async function broadcastTo (uris: string[], data: any, byActor: ActorModel) { | 109 | function broadcastTo (uris: string[], data: any, byActor: ActorModel) { |
104 | if (uris.length === 0) return undefined | 110 | if (uris.length === 0) return undefined |
105 | 111 | ||
106 | logger.debug('Creating broadcast job.', { uris }) | 112 | logger.debug('Creating broadcast job.', { uris }) |
@@ -114,7 +120,7 @@ async function broadcastTo (uris: string[], data: any, byActor: ActorModel) { | |||
114 | return JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload }) | 120 | return JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload }) |
115 | } | 121 | } |
116 | 122 | ||
117 | async function unicastTo (data: any, byActor: ActorModel, toActorUrl: string) { | 123 | function unicastTo (data: any, byActor: ActorModel, toActorUrl: string) { |
118 | logger.debug('Creating unicast job.', { uri: toActorUrl }) | 124 | logger.debug('Creating unicast job.', { uri: toActorUrl }) |
119 | 125 | ||
120 | const payload = { | 126 | const payload = { |
@@ -123,7 +129,7 @@ async function unicastTo (data: any, byActor: ActorModel, toActorUrl: string) { | |||
123 | body: data | 129 | body: data |
124 | } | 130 | } |
125 | 131 | ||
126 | return JobQueue.Instance.createJob({ type: 'activitypub-http-unicast', payload }) | 132 | JobQueue.Instance.createJob({ type: 'activitypub-http-unicast', payload }) |
127 | } | 133 | } |
128 | 134 | ||
129 | // --------------------------------------------------------------------------- | 135 | // --------------------------------------------------------------------------- |