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'
7 import { MActorFollowersUrl, MActorLight, MActorUrl, MCommentOwner, MCommentOwnerVideo, MVideoId } from '../../typings/models'
9 function getRemoteVideoAudience (accountActor: MActorUrl, actorsInvolvedInVideo: MActorFollowersUrl[]): ActivityAudience {
11 to: [ accountActor.url ],
12 cc: actorsInvolvedInVideo.map(a => a.followersUrl)
16 function getVideoCommentAudience (
17 videoComment: MCommentOwnerVideo,
18 threadParentComments: MCommentOwner[],
19 actorsInvolvedInVideo: MActorFollowersUrl[],
22 const to = [ ACTIVITY_PUB.PUBLIC ]
23 const cc: string[] = []
25 // Owner of the video we comment
26 if (isOrigin === false) {
27 cc.push(videoComment.Video.VideoChannel.Account.Actor.url)
30 // Followers of the poster
31 cc.push(videoComment.Account.Actor.followersUrl)
33 // Send to actors we reply to
34 for (const parentComment of threadParentComments) {
35 cc.push(parentComment.Account.Actor.url)
40 cc: cc.concat(actorsInvolvedInVideo.map(a => a.followersUrl))
44 function getAudienceFromFollowersOf (actorsInvolvedInObject: MActorFollowersUrl[]): ActivityAudience {
46 to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)),
51 async function getActorsInvolvedInVideo (video: MVideoId, t: Transaction) {
52 const actors: MActorLight[] = await VideoShareModel.loadActorsByShare(video.id, t)
54 const videoAll = video as VideoModel
56 const videoActor = videoAll.VideoChannel && videoAll.VideoChannel.Account
57 ? videoAll.VideoChannel.Account.Actor
58 : await ActorModel.loadFromAccountByVideoId(video.id, t)
60 actors.push(videoActor)
65 function getAudience (actorSender: MActorFollowersUrl, isPublic = true) {
66 return buildAudience([ actorSender.followersUrl ], isPublic)
69 function buildAudience (followerUrls: string[], isPublic = true) {
74 to = [ ACTIVITY_PUB.PUBLIC ]
84 function audiencify<T> (object: T, audience: ActivityAudience) {
85 return Object.assign(object, audience)
88 // ---------------------------------------------------------------------------
93 getRemoteVideoAudience,
94 getActorsInvolvedInVideo,
95 getAudienceFromFollowersOf,
97 getVideoCommentAudience