]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/audience.ts
Stronger actor association typing in AP functions
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / audience.ts
index a86428461c365ca35217acd2f3fe266e859348be..0e3d78590dfa78be4bc1a65a9a3a9a1f18e2d61e 100644 (file)
@@ -1,10 +1,11 @@
 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 getRemoteVideoAudience (video: VideoModel, actorsInvolvedInVideo: ActorModel[]): ActivityAudience {
   return {
@@ -50,12 +51,17 @@ function getAudienceFromFollowersOf (actorsInvolvedInObject: ActorModel[]): Acti
 
 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)
 }