]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/send/send-like.ts
Fix cc field in classic audience
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-like.ts
index 7e0c73796525fe322d6e5867ee0a1f72501ebbe2..fb2b4aaf87132f356af319c6930a4887b2da0cf3 100644 (file)
@@ -4,6 +4,7 @@ import { ActorModel } from '../../../models/activitypub/actor'
 import { VideoModel } from '../../../models/video/video'
 import { getVideoLikeActivityPubUrl } from '../url'
 import {
+  audiencify,
   broadcastToFollowers,
   getActorsInvolvedInVideo,
   getAudience,
@@ -12,20 +13,20 @@ import {
   unicastTo
 } from './misc'
 
-async function sendLikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
+async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
   const url = getVideoLikeActivityPubUrl(byActor, video)
 
   const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
-  const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
-  const data = await likeActivityData(url, byActor, video, t, audience)
 
-  return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t)
-}
+  // Send to origin
+  if (video.isOwned() === false) {
+    const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
+    const data = await likeActivityData(url, byActor, video, t, audience)
 
-async function sendLikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
-  const url = getVideoLikeActivityPubUrl(byActor, video)
+    return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
+  }
 
-  const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
+  // Send to followers
   const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
   const data = await likeActivityData(url, byActor, video, t, audience)
 
@@ -44,20 +45,17 @@ async function likeActivityData (
     audience = await getAudience(byActor, t)
   }
 
-  return {
-    type: 'Like',
+  return audiencify({
+    type: 'Like' as 'Like',
     id: url,
     actor: byActor.url,
-    to: audience.to,
-    cc: audience.cc,
     object: video.url
-  }
+  }, audience)
 }
 
 // ---------------------------------------------------------------------------
 
 export {
-  sendLikeToOrigin,
-  sendLikeToVideoFollowers,
+  sendLike,
   likeActivityData
 }