import { VideoModel } from '../../../models/video/video'
import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience'
import { getServerActor } from '../../../helpers/utils'
+import { afterCommitIfTransaction } from '../../../helpers/database-utils'
async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: {
byActor: ActorModel,
const audience = getRemoteVideoAudience(options.video, actorsInvolvedInVideo)
const activity = activityBuilder(audience)
- return unicastTo(activity, options.byActor, options.video.VideoChannel.Account.Actor.sharedInboxUrl)
+ return afterCommitIfTransaction(options.transaction, () => {
+ return unicastTo(activity, options.byActor, options.video.VideoChannel.Account.Actor.sharedInboxUrl)
+ })
}
// Send to followers
const activity = activityBuilder(audience)
const actorsException = [ options.byActor ]
+
return broadcastToFollowers(activity, options.byActor, actorsInvolvedInVideo, options.transaction, actorsException)
}
uris,
body: activity
}
- return JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload })
+ return afterCommitIfTransaction(t, () => JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload }))
}
async function broadcastToFollowers (
actorsException: ActorModel[] = []
) {
const uris = await computeFollowerUris(toFollowersOf, actorsException, t)
- return broadcastTo(uris, data, byActor)
+
+ return afterCommitIfTransaction(t, () => broadcastTo(uris, data, byActor))
}
async function broadcastToActors (
data: any,
byActor: ActorModel,
toActors: ActorModel[],
+ t?: Transaction,
actorsException: ActorModel[] = []
) {
const uris = await computeUris(toActors, actorsException)
- return broadcastTo(uris, data, byActor)
+ return afterCommitIfTransaction(t, () => broadcastTo(uris, data, byActor))
}
-async function broadcastTo (uris: string[], data: any, byActor: ActorModel) {
+function broadcastTo (uris: string[], data: any, byActor: ActorModel) {
if (uris.length === 0) return undefined
logger.debug('Creating broadcast job.', { uris })
return JobQueue.Instance.createJob({ type: 'activitypub-http-broadcast', payload })
}
-async function unicastTo (data: any, byActor: ActorModel, toActorUrl: string) {
+function unicastTo (data: any, byActor: ActorModel, toActorUrl: string) {
logger.debug('Creating unicast job.', { uri: toActorUrl })
const payload = {
body: data
}
- return JobQueue.Instance.createJob({ type: 'activitypub-http-unicast', payload })
+ JobQueue.Instance.createJob({ type: 'activitypub-http-unicast', payload })
}
// ---------------------------------------------------------------------------