+import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience'
+import { getServerActor } from '../../../helpers/utils'
+import { afterCommitIfTransaction } from '../../../helpers/database-utils'
+import { ActorFollowerException, ActorModelId, ActorModelOnly } from '../../../typings/models'
+
+async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: {
+ byActor: ActorModelOnly,
+ video: VideoModel,
+ transaction?: Transaction
+}) {
+ const { byActor, video, transaction } = options
+
+ const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, transaction)
+
+ // Send to origin
+ if (video.isOwned() === false) {
+ const audience = getRemoteVideoAudience(video, actorsInvolvedInVideo)
+ const activity = activityBuilder(audience)
+
+ return afterCommitIfTransaction(transaction, () => {
+ return unicastTo(activity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
+ })
+ }
+
+ // Send to followers
+ const audience = getAudienceFromFollowersOf(actorsInvolvedInVideo)
+ const activity = activityBuilder(audience)
+
+ const actorsException = [ byActor ]
+
+ return broadcastToFollowers(activity, byActor, actorsInvolvedInVideo, transaction, actorsException)
+}