1 import { Transaction } from 'sequelize'
2 import { ACTIVITY_PUB } from '@server/initializers/constants'
3 import { ActorModel } from '@server/models/actor/actor'
4 import { VideoModel } from '@server/models/video/video'
5 import { VideoShareModel } from '@server/models/video/video-share'
6 import { MActorFollowersUrl, MActorUrl, MCommentOwner, MCommentOwnerVideo, MVideoId } from '@server/types/models'
7 import { ActivityAudience } from '@shared/models'
9 function getOriginVideoAudience (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 if (parentComment.isDeleted()) continue
37 cc.push(parentComment.Account.Actor.url)
42 cc: cc.concat(actorsInvolvedInVideo.map(a => a.followersUrl))
46 function getAudienceFromFollowersOf (actorsInvolvedInObject: MActorFollowersUrl[]): ActivityAudience {
48 to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)),
53 async function getActorsInvolvedInVideo (video: MVideoId, t: Transaction) {
54 const actors = await VideoShareModel.listActorIdsAndFollowerUrlsByShare(video.id, t)
56 const videoAll = video as VideoModel
58 const videoActor = videoAll.VideoChannel?.Account
59 ? videoAll.VideoChannel.Account.Actor
60 : await ActorModel.loadAccountActorFollowerUrlByVideoId(video.id, t)
62 actors.push(videoActor)
67 // ---------------------------------------------------------------------------
70 getOriginVideoAudience,
71 getActorsInvolvedInVideo,
72 getAudienceFromFollowersOf,
73 getVideoCommentAudience