aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-29 11:59:29 +0200
committerChocobozzz <me@florianbigard.com>2019-07-29 13:40:39 +0200
commit2284f202070aa2e49156cc52b3b1596a7d5aadec (patch)
tree77aeb00016734667f8ff32a98ea8b4a6ed3ca31e /server/lib/activitypub/send/utils.ts
parent112be80ebdf96ef6a27420c1c6a10097388731a9 (diff)
downloadPeerTube-2284f202070aa2e49156cc52b3b1596a7d5aadec.tar.gz
PeerTube-2284f202070aa2e49156cc52b3b1596a7d5aadec.tar.zst
PeerTube-2284f202070aa2e49156cc52b3b1596a7d5aadec.zip
Add gitlab ci support
Diffstat (limited to 'server/lib/activitypub/send/utils.ts')
-rw-r--r--server/lib/activitypub/send/utils.ts20
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'
7import { VideoModel } from '../../../models/video/video' 7import { VideoModel } from '../../../models/video/video'
8import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience' 8import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience'
9import { getServerActor } from '../../../helpers/utils' 9import { getServerActor } from '../../../helpers/utils'
10import { afterCommitIfTransaction } from '../../../helpers/database-utils'
10 11
11async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: { 12async 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
82async function broadcastToFollowers ( 86async 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
93async function broadcastToActors ( 98async 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
103async function broadcastTo (uris: string[], data: any, byActor: ActorModel) { 109function 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
117async function unicastTo (data: any, byActor: ActorModel, toActorUrl: string) { 123function 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// ---------------------------------------------------------------------------