X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Faudience.ts;h=0e3d78590dfa78be4bc1a65a9a3a9a1f18e2d61e;hb=5224c394b3bbac6ec1543e41fa0ec6db436e84fa;hp=7b4067c11c62eeee8318f8667274e5fbb8211729;hpb=c1e791bad0b079af67398f6407221e6dcbb573dd;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/audience.ts b/server/lib/activitypub/audience.ts index 7b4067c11..0e3d78590 100644 --- a/server/lib/activitypub/audience.ts +++ b/server/lib/activitypub/audience.ts @@ -1,12 +1,13 @@ import { Transaction } from 'sequelize' import { ActivityAudience } from '../../../shared/models/activitypub' -import { ACTIVITY_PUB } from '../../initializers' +import { ACTIVITY_PUB } from '../../initializers/constants' import { ActorModel } from '../../models/activitypub/actor' import { VideoModel } from '../../models/video/video' import { VideoCommentModel } from '../../models/video/video-comment' import { VideoShareModel } from '../../models/video/video-share' +import { ActorModelOnly } from '../../typings/models' -function getVideoAudience (video: VideoModel, actorsInvolvedInVideo: ActorModel[]) { +function getRemoteVideoAudience (video: VideoModel, actorsInvolvedInVideo: ActorModel[]): ActivityAudience { return { to: [ video.VideoChannel.Account.Actor.url ], cc: actorsInvolvedInVideo.map(a => a.followersUrl) @@ -18,7 +19,7 @@ function getVideoCommentAudience ( threadParentComments: VideoCommentModel[], actorsInvolvedInVideo: ActorModel[], isOrigin = false -) { +): ActivityAudience { const to = [ ACTIVITY_PUB.PUBLIC ] const cc: string[] = [] @@ -41,7 +42,7 @@ function getVideoCommentAudience ( } } -function getObjectFollowersAudience (actorsInvolvedInObject: ActorModel[]) { +function getAudienceFromFollowersOf (actorsInvolvedInObject: ActorModel[]): ActivityAudience { return { to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)), cc: [] @@ -50,12 +51,17 @@ function getObjectFollowersAudience (actorsInvolvedInObject: ActorModel[]) { async function getActorsInvolvedInVideo (video: VideoModel, t: Transaction) { const actors = await VideoShareModel.loadActorsByShare(video.id, t) - actors.push(video.VideoChannel.Account.Actor) + + const videoActor = video.VideoChannel && video.VideoChannel.Account + ? video.VideoChannel.Account.Actor + : await ActorModel.loadAccountActorByVideoId(video.id, t) + + actors.push(videoActor) return actors } -function getAudience (actorSender: ActorModel, isPublic = true) { +function getAudience (actorSender: ActorModelOnly, isPublic = true) { return buildAudience([ actorSender.followersUrl ], isPublic) } @@ -83,9 +89,9 @@ function audiencify (object: T, audience: ActivityAudience) { export { buildAudience, getAudience, - getVideoAudience, + getRemoteVideoAudience, getActorsInvolvedInVideo, - getObjectFollowersAudience, + getAudienceFromFollowersOf, audiencify, getVideoCommentAudience }