1 import { Transaction } from 'sequelize'
2 import { ActivityAudience } from '../../../shared/models/activitypub'
3 import { ACTIVITY_PUB } from '../../initializers'
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'
9 function getVideoAudience (video: VideoModel, actorsInvolvedInVideo: ActorModel[]) {
11 to: [ video.VideoChannel.Account.Actor.url ],
12 cc: actorsInvolvedInVideo.map(a => a.followersUrl)
16 function getVideoCommentAudience (
17 videoComment: VideoCommentModel,
18 threadParentComments: VideoCommentModel[],
19 actorsInvolvedInVideo: ActorModel[],
22 const to = [ ACTIVITY_PUB.PUBLIC ]
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 getObjectFollowersAudience (actorsInvolvedInObject: ActorModel[]) {
46 to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)),
51 async function getActorsInvolvedInVideo (video: VideoModel, t: Transaction) {
52 const actors = await VideoShareModel.loadActorsByShare(video.id, t)
53 actors.push(video.VideoChannel.Account.Actor)
58 async function getAudience (actorSender: ActorModel, t: Transaction, isPublic = true) {
59 return buildAudience([ actorSender.followersUrl ], isPublic)
62 function buildAudience (followerInboxUrls: string[], isPublic = true) {
63 // Thanks Mastodon: https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/tag_manager.rb#L47
68 to = [ ACTIVITY_PUB.PUBLIC ]
69 cc = followerInboxUrls
78 function audiencify <T> (object: T, audience: ActivityAudience) {
79 return Object.assign(object, audience)
82 // ---------------------------------------------------------------------------
88 getActorsInvolvedInVideo,
89 getObjectFollowersAudience,
91 getVideoCommentAudience