import { Transaction } from 'sequelize' ; import { ActivityAudience } from '../../../shared/models/activitypub' ; import { ACTIVITY_PUB } from '../../initializers/constants' ; import { ActorModel } from '../../models/actor/actor' ; import { VideoModel } from '../../models/video/video' ; import { VideoShareModel } from '../../models/video/video-share' ; import { MActorFollowersUrl , MActorLight , MActorUrl , MCommentOwner , MCommentOwnerVideo , MVideoId } from '../../types/models' ; function getRemoteVideoAudience ( accountActor , actorsInvolvedInVideo ) { return { to : [ accountActor . url ] , cc : actorsInvolvedInVideo . map ( a => a . followersUrl ) } ; } function getVideoCommentAudience ( videoComment , threadParentComments , actorsInvolvedInVideo , isOrigin = false ) { const to = [ ACTIVITY_PUB . PUBLIC ] ; const cc = [ ] ; if ( isOrigin === false ) { cc . push ( videoComment . Video . VideoChannel . Account . Actor . url ) ; } cc . push ( videoComment . Account . Actor . followersUrl ) ; for ( const parentComment of threadParentComments ) { if ( parentComment . isDeleted ( ) ) continue ; cc . push ( parentComment . Account . Actor . url ) ; } return { to , cc : cc . concat ( actorsInvolvedInVideo . map ( a => a . followersUrl ) ) } ; } function getAudienceFromFollowersOf ( actorsInvolvedInObject ) { return { to : [ ACTIVITY_PUB . PUBLIC ] . concat ( actorsInvolvedInObject . map ( a => a . followersUrl ) ) , cc : [ ] } ; } async function getActorsInvolvedInVideo ( video , t ) { const actors = await VideoShareModel . loadActorsByShare ( video . id , t ) ; const videoAll = video as VideoModel ; const videoActor = videoAll . VideoChannel ?. Account ? videoAll . VideoChannel . Account . Actor : await ActorModel . loadFromAccountByVideoId ( video . id , t ) ; actors . push ( videoActor ) ; return actors ; } function getAudience ( actorSender , isPublic = true ) { return buildAudience ( [ actorSender . followersUrl ] , isPublic ) ; } function buildAudience ( followerUrls , isPublic = true ) { let to = [ ] ; let cc = [ ] ; if ( isPublic ) { to = [ ACTIVITY_PUB . PUBLIC ] ; cc = followerUrls ; } else { to = [ ] ; cc = [ ] ; } return { to , cc } ; } function audiencify < T > ( object , audience ) { return Object . assign ( object , audience ) ; } export { buildAudience , getAudience , getRemoteVideoAudience , getActorsInvolvedInVideo , getAudienceFromFollowersOf , audiencify , getVideoCommentAudience } ;