]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/audience.ts
Prevent invalid watch sections
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / audience.ts
index 10277eca7bae7c437254c1134a3d0f7f33f1ba31..6f54913875858aff5b10f5131282c2137248a34d 100644 (file)
@@ -1,66 +1,8 @@
-import { Transaction } from 'sequelize'
 import { ActivityAudience } from '../../../shared/models/activitypub'
-import { ACTIVITY_PUB } from '../../initializers'
-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 { ACTIVITY_PUB } from '../../initializers/constants'
+import { MActorFollowersUrl } from '../../types/models'
 
-function getRemoteVideoAudience (video: VideoModel, actorsInvolvedInVideo: ActorModel[]): ActivityAudience {
-  return {
-    to: [ video.VideoChannel.Account.Actor.url ],
-    cc: actorsInvolvedInVideo.map(a => a.followersUrl)
-  }
-}
-
-function getVideoCommentAudience (
-  videoComment: VideoCommentModel,
-  threadParentComments: VideoCommentModel[],
-  actorsInvolvedInVideo: ActorModel[],
-  isOrigin = false
-): ActivityAudience {
-  const to = [ ACTIVITY_PUB.PUBLIC ]
-  const cc: string[] = []
-
-  // Owner of the video we comment
-  if (isOrigin === false) {
-    cc.push(videoComment.Video.VideoChannel.Account.Actor.url)
-  }
-
-  // Followers of the poster
-  cc.push(videoComment.Account.Actor.followersUrl)
-
-  // Send to actors we reply to
-  for (const parentComment of threadParentComments) {
-    cc.push(parentComment.Account.Actor.url)
-  }
-
-  return {
-    to,
-    cc: cc.concat(actorsInvolvedInVideo.map(a => a.followersUrl))
-  }
-}
-
-function getAudienceFromFollowersOf (actorsInvolvedInObject: ActorModel[]): ActivityAudience {
-  return {
-    to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)),
-    cc: []
-  }
-}
-
-async function getActorsInvolvedInVideo (video: VideoModel, t: Transaction) {
-  const actors = await VideoShareModel.loadActorsByShare(video.id, t)
-
-  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: MActorFollowersUrl, isPublic = true) {
   return buildAudience([ actorSender.followersUrl ], isPublic)
 }
 
@@ -80,7 +22,7 @@ function buildAudience (followerUrls: string[], isPublic = true) {
 }
 
 function audiencify<T> (object: T, audience: ActivityAudience) {
-  return Object.assign(object, audience)
+  return { ...audience, ...object }
 }
 
 // ---------------------------------------------------------------------------
@@ -88,9 +30,5 @@ function audiencify<T> (object: T, audience: ActivityAudience) {
 export {
   buildAudience,
   getAudience,
-  getRemoteVideoAudience,
-  getActorsInvolvedInVideo,
-  getAudienceFromFollowersOf,
-  audiencify,
-  getVideoCommentAudience
+  audiencify
 }