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 { VideoShareModel } from '../../models/video/video-share'
15 } from '../../typings/models'
17 function getRemoteVideoAudience (video: MVideoAccountLight, actorsInvolvedInVideo: MActorFollowersUrl[]): ActivityAudience {
19 to: [ video.VideoChannel.Account.Actor.url ],
20 cc: actorsInvolvedInVideo.map(a => a.followersUrl)
24 function getVideoCommentAudience (
25 videoComment: MCommentOwnerVideo,
26 threadParentComments: MCommentOwner[],
27 actorsInvolvedInVideo: MActorFollowersUrl[],
30 const to = [ ACTIVITY_PUB.PUBLIC ]
31 const cc: string[] = []
33 // Owner of the video we comment
34 if (isOrigin === false) {
35 cc.push(videoComment.Video.VideoChannel.Account.Actor.url)
38 // Followers of the poster
39 cc.push(videoComment.Account.Actor.followersUrl)
41 // Send to actors we reply to
42 for (const parentComment of threadParentComments) {
43 cc.push(parentComment.Account.Actor.url)
48 cc: cc.concat(actorsInvolvedInVideo.map(a => a.followersUrl))
52 function getAudienceFromFollowersOf (actorsInvolvedInObject: MActorFollowersUrl[]): ActivityAudience {
54 to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)),
59 async function getActorsInvolvedInVideo (video: MVideoId, t: Transaction) {
60 const actors: MActorLight[] = await VideoShareModel.loadActorsByShare(video.id, t)
62 const videoAll = video as VideoModel
64 const videoActor = videoAll.VideoChannel && videoAll.VideoChannel.Account
65 ? videoAll.VideoChannel.Account.Actor
66 : await ActorModel.loadFromAccountByVideoId(video.id, t)
68 actors.push(videoActor)
73 function getAudience (actorSender: MActorFollowersUrl, isPublic = true) {
74 return buildAudience([ actorSender.followersUrl ], isPublic)
77 function buildAudience (followerUrls: string[], isPublic = true) {
82 to = [ ACTIVITY_PUB.PUBLIC ]
92 function audiencify<T> (object: T, audience: ActivityAudience) {
93 return Object.assign(object, audience)
96 // ---------------------------------------------------------------------------
101 getRemoteVideoAudience,
102 getActorsInvolvedInVideo,
103 getAudienceFromFollowersOf,
105 getVideoCommentAudience