1 import { Transaction } from 'sequelize'
2 import { ActivityAudience } from '../../../shared/models/activitypub'
3 import { ACTIVITY_PUB } from '../../initializers/constants'
4 import { ActorModel } from '../../models/activitypub/actor'
5 import { VideoModel } from '../../models/video/video'
6 import { VideoCommentModel } from '../../models/video/video-comment'
7 import { VideoShareModel } from '../../models/video/video-share'
8 import { ActorModelOnly } from '../../typings/models'
10 function getRemoteVideoAudience (video: VideoModel, actorsInvolvedInVideo: ActorModel[]): ActivityAudience {
12 to: [ video.VideoChannel.Account.Actor.url ],
13 cc: actorsInvolvedInVideo.map(a => a.followersUrl)
17 function getVideoCommentAudience (
18 videoComment: VideoCommentModel,
19 threadParentComments: VideoCommentModel[],
20 actorsInvolvedInVideo: ActorModel[],
23 const to = [ ACTIVITY_PUB.PUBLIC ]
24 const cc: string[] = []
26 // Owner of the video we comment
27 if (isOrigin === false) {
28 cc.push(videoComment.Video.VideoChannel.Account.Actor.url)
31 // Followers of the poster
32 cc.push(videoComment.Account.Actor.followersUrl)
34 // Send to actors we reply to
35 for (const parentComment of threadParentComments) {
36 cc.push(parentComment.Account.Actor.url)
41 cc: cc.concat(actorsInvolvedInVideo.map(a => a.followersUrl))
45 function getAudienceFromFollowersOf (actorsInvolvedInObject: ActorModel[]): ActivityAudience {
47 to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)),
52 async function getActorsInvolvedInVideo (video: VideoModel, t: Transaction) {
53 const actors = await VideoShareModel.loadActorsByShare(video.id, t)
55 const videoActor = video.VideoChannel && video.VideoChannel.Account
56 ? video.VideoChannel.Account.Actor
57 : await ActorModel.loadAccountActorByVideoId(video.id, t)
59 actors.push(videoActor)
64 function getAudience (actorSender: ActorModelOnly, isPublic = true) {
65 return buildAudience([ actorSender.followersUrl ], isPublic)
68 function buildAudience (followerUrls: string[], isPublic = true) {
73 to = [ ACTIVITY_PUB.PUBLIC ]
83 function audiencify<T> (object: T, audience: ActivityAudience) {
84 return Object.assign(object, audience)
87 // ---------------------------------------------------------------------------
92 getRemoteVideoAudience,
93 getActorsInvolvedInVideo,
94 getAudienceFromFollowersOf,
96 getVideoCommentAudience