]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/audience.ts
More robust channel change federation
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / audience.ts
index 39caeef7b78fc7a1f390f15310350695864fae14..2986714d309c4290b96d3bd11f6f9fd7040c6028 100644 (file)
@@ -4,19 +4,11 @@ import { ACTIVITY_PUB } from '../../initializers/constants'
 import { ActorModel } from '../../models/activitypub/actor'
 import { VideoModel } from '../../models/video/video'
 import { VideoShareModel } from '../../models/video/video-share'
-import {
-  MActorFollowersUrl,
-  MActorLight,
-  MCommentOwner,
-  MCommentOwnerVideo,
-  MVideo,
-  MVideoAccountLight,
-  MVideoId
-} from '../../typings/models'
-
-function getRemoteVideoAudience (video: MVideoAccountLight, actorsInvolvedInVideo: MActorFollowersUrl[]): ActivityAudience {
+import { MActorFollowersUrl, MActorLight, MActorUrl, MCommentOwner, MCommentOwnerVideo, MVideoId } from '../../types/models'
+
+function getRemoteVideoAudience (accountActor: MActorUrl, actorsInvolvedInVideo: MActorFollowersUrl[]): ActivityAudience {
   return {
-    to: [ video.VideoChannel.Account.Actor.url ],
+    to: [ accountActor.url ],
     cc: actorsInvolvedInVideo.map(a => a.followersUrl)
   }
 }
@@ -40,6 +32,8 @@ function getVideoCommentAudience (
 
   // Send to actors we reply to
   for (const parentComment of threadParentComments) {
+    if (parentComment.isDeleted()) continue
+
     cc.push(parentComment.Account.Actor.url)
   }
 
@@ -61,7 +55,7 @@ async function getActorsInvolvedInVideo (video: MVideoId, t: Transaction) {
 
   const videoAll = video as VideoModel
 
-  const videoActor = videoAll.VideoChannel && videoAll.VideoChannel.Account
+  const videoActor = videoAll.VideoChannel?.Account
     ? videoAll.VideoChannel.Account.Actor
     : await ActorModel.loadFromAccountByVideoId(video.id, t)