X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Faudience.ts;h=10277eca7bae7c437254c1134a3d0f7f33f1ba31;hb=b88a459664957d6ab9c417a6749b611e6cc6c0e2;hp=7164135b6ff77c2bfdab16113e90b184fb978b75;hpb=2186386cca113506791583cb07d6ccacba7af4e0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/audience.ts b/server/lib/activitypub/audience.ts index 7164135b6..10277eca7 100644 --- a/server/lib/activitypub/audience.ts +++ b/server/lib/activitypub/audience.ts @@ -6,7 +6,7 @@ import { VideoModel } from '../../models/video/video' import { VideoCommentModel } from '../../models/video/video-comment' import { VideoShareModel } from '../../models/video/video-share' -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,9 +18,9 @@ function getVideoCommentAudience ( threadParentComments: VideoCommentModel[], actorsInvolvedInVideo: ActorModel[], isOrigin = false -) { +): ActivityAudience { const to = [ ACTIVITY_PUB.PUBLIC ] - const cc = [] + const cc: string[] = [] // Owner of the video we comment if (isOrigin === false) { @@ -41,7 +41,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,7 +50,12 @@ 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 } @@ -60,8 +65,8 @@ function getAudience (actorSender: ActorModel, isPublic = true) { } function buildAudience (followerUrls: string[], isPublic = true) { - let to = [] - let cc = [] + let to: string[] = [] + let cc: string[] = [] if (isPublic) { to = [ ACTIVITY_PUB.PUBLIC ] @@ -83,9 +88,9 @@ function audiencify (object: T, audience: ActivityAudience) { export { buildAudience, getAudience, - getVideoAudience, + getRemoteVideoAudience, getActorsInvolvedInVideo, - getObjectFollowersAudience, + getAudienceFromFollowersOf, audiencify, getVideoCommentAudience }