diff options
Diffstat (limited to 'server/lib/activitypub/send/utils.ts')
-rw-r--r-- | server/lib/activitypub/send/utils.ts | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/server/lib/activitypub/send/utils.ts b/server/lib/activitypub/send/utils.ts index 6fb4efd60..ce932eb1f 100644 --- a/server/lib/activitypub/send/utils.ts +++ b/server/lib/activitypub/send/utils.ts | |||
@@ -8,13 +8,15 @@ import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAud | |||
8 | import { getServerActor } from '../../../helpers/utils' | 8 | import { getServerActor } from '../../../helpers/utils' |
9 | import { afterCommitIfTransaction } from '../../../helpers/database-utils' | 9 | import { afterCommitIfTransaction } from '../../../helpers/database-utils' |
10 | import { MActorWithInboxes, MActor, MActorId, MActorLight, MVideo, MVideoAccountLight } from '../../../typings/models' | 10 | import { MActorWithInboxes, MActor, MActorId, MActorLight, MVideo, MVideoAccountLight } from '../../../typings/models' |
11 | import { ContextType } from '@server/helpers/activitypub' | ||
11 | 12 | ||
12 | async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: { | 13 | async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: { |
13 | byActor: MActorLight | 14 | byActor: MActorLight |
14 | video: MVideoAccountLight | 15 | video: MVideoAccountLight |
15 | transaction?: Transaction | 16 | transaction?: Transaction, |
17 | contextType?: ContextType | ||
16 | }) { | 18 | }) { |
17 | const { byActor, video, transaction } = options | 19 | const { byActor, video, transaction, contextType } = options |
18 | 20 | ||
19 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, transaction) | 21 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, transaction) |
20 | 22 | ||
@@ -24,7 +26,7 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud | |||
24 | const activity = activityBuilder(audience) | 26 | const activity = activityBuilder(audience) |
25 | 27 | ||
26 | return afterCommitIfTransaction(transaction, () => { | 28 | return afterCommitIfTransaction(transaction, () => { |
27 | return unicastTo(activity, byActor, video.VideoChannel.Account.Actor.getSharedInbox()) | 29 | return unicastTo(activity, byActor, video.VideoChannel.Account.Actor.getSharedInbox(), contextType) |
28 | }) | 30 | }) |
29 | } | 31 | } |
30 | 32 | ||
@@ -34,7 +36,7 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud | |||
34 | 36 | ||
35 | const actorsException = [ byActor ] | 37 | const actorsException = [ byActor ] |
36 | 38 | ||
37 | return broadcastToFollowers(activity, byActor, actorsInvolvedInVideo, transaction, actorsException) | 39 | return broadcastToFollowers(activity, byActor, actorsInvolvedInVideo, transaction, actorsException, contextType) |
38 | } | 40 | } |
39 | 41 | ||
40 | async function forwardVideoRelatedActivity ( | 42 | async function forwardVideoRelatedActivity ( |
@@ -90,11 +92,12 @@ async function broadcastToFollowers ( | |||
90 | byActor: MActorId, | 92 | byActor: MActorId, |
91 | toFollowersOf: MActorId[], | 93 | toFollowersOf: MActorId[], |
92 | t: Transaction, | 94 | t: Transaction, |
93 | actorsException: MActorWithInboxes[] = [] | 95 | actorsException: MActorWithInboxes[] = [], |
96 | contextType?: ContextType | ||
94 | ) { | 97 | ) { |
95 | const uris = await computeFollowerUris(toFollowersOf, actorsException, t) | 98 | const uris = await computeFollowerUris(toFollowersOf, actorsException, t) |
96 | 99 | ||
97 | return afterCommitIfTransaction(t, () => broadcastTo(uris, data, byActor)) | 100 | return afterCommitIfTransaction(t, () => broadcastTo(uris, data, byActor, contextType)) |
98 | } | 101 | } |
99 | 102 | ||
100 | async function broadcastToActors ( | 103 | async function broadcastToActors ( |
@@ -102,13 +105,14 @@ async function broadcastToActors ( | |||
102 | byActor: MActorId, | 105 | byActor: MActorId, |
103 | toActors: MActor[], | 106 | toActors: MActor[], |
104 | t?: Transaction, | 107 | t?: Transaction, |
105 | actorsException: MActorWithInboxes[] = [] | 108 | actorsException: MActorWithInboxes[] = [], |
109 | contextType?: ContextType | ||
106 | ) { | 110 | ) { |
107 | const uris = await computeUris(toActors, actorsException) | 111 | const uris = await computeUris(toActors, actorsException) |
108 | return afterCommitIfTransaction(t, () => broadcastTo(uris, data, byActor)) | 112 | return afterCommitIfTransaction(t, () => broadcastTo(uris, data, byActor, contextType)) |
109 | } | 113 | } |
110 | 114 | ||
111 | function broadcastTo (uris: string[], data: any, byActor: MActorId) { | 115 | function broadcastTo (uris: string[], data: any, byActor: MActorId, contextType?: ContextType) { |
112 | if (uris.length === 0) return undefined | 116 | if (uris.length === 0) return undefined |
113 | 117 | ||
114 | logger.debug('Creating broadcast job.', { uris }) | 118 | logger.debug('Creating broadcast job.', { uris }) |
@@ -116,19 +120,21 @@ function broadcastTo (uris: string[], data: any, byActor: MActorId) { | |||
116 | const payload = { | 120 | const payload = { |
117 | uris, | 121 | uris, |
118 | signatureActorId: byActor.id, | 122 | signatureActorId: byActor.id, |
119 | body: data | 123 | body: data, |
124 | contextType | ||
120 | } | 125 | } |
121 | 126 | ||
122 | return JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload }) | 127 | return JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload }) |
123 | } | 128 | } |
124 | 129 | ||
125 | function unicastTo (data: any, byActor: MActorId, toActorUrl: string) { | 130 | function unicastTo (data: any, byActor: MActorId, toActorUrl: string, contextType?: ContextType) { |
126 | logger.debug('Creating unicast job.', { uri: toActorUrl }) | 131 | logger.debug('Creating unicast job.', { uri: toActorUrl }) |
127 | 132 | ||
128 | const payload = { | 133 | const payload = { |
129 | uri: toActorUrl, | 134 | uri: toActorUrl, |
130 | signatureActorId: byActor.id, | 135 | signatureActorId: byActor.id, |
131 | body: data | 136 | body: data, |
137 | contextType | ||
132 | } | 138 | } |
133 | 139 | ||
134 | JobQueue.Instance.createJob({ type: 'activitypub-http-unicast', payload }) | 140 | JobQueue.Instance.createJob({ type: 'activitypub-http-unicast', payload }) |