]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/send/send-like.ts
Add more info logging
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-like.ts
index 78ed1aaf284774a92f4ac32e8ec951928f8a7d38..83225f5df1d62186561e40a43953815d35773c13 100644 (file)
@@ -3,60 +3,50 @@ import { ActivityAudience, ActivityLike } from '../../../../shared/models/activi
 import { ActorModel } from '../../../models/activitypub/actor'
 import { VideoModel } from '../../../models/video/video'
 import { getVideoLikeActivityPubUrl } from '../url'
-import {
-  audiencify,
-  broadcastToFollowers,
-  getActorsInvolvedInVideo,
-  getAudience,
-  getObjectFollowersAudience,
-  getOriginVideoAudience,
-  unicastTo
-} from './misc'
-
-async function sendLikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
+import { broadcastToFollowers, unicastTo } from './utils'
+import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getVideoAudience } from '../audience'
+import { logger } from '../../../helpers/logger'
+
+async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
+  logger.info('Creating job to like %s.', video.url)
+
   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)
-}
+  // Send to origin
+  if (video.isOwned() === false) {
+    const audience = getVideoAudience(video, accountsInvolvedInVideo)
+    const data = likeActivityData(url, byActor, video, 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)
+  const data = likeActivityData(url, byActor, video, audience)
 
   const followersException = [ byActor ]
   return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException)
 }
 
-async function likeActivityData (
-  url: string,
-  byActor: ActorModel,
-  video: VideoModel,
-  t: Transaction,
-  audience?: ActivityAudience
-): Promise<ActivityLike> {
-  if (!audience) {
-    audience = await getAudience(byActor, t)
-  }
-
-  return audiencify({
-    type: 'Like',
-    id: url,
-    actor: byActor.url,
-    object: video.url
-  }, audience)
+function likeActivityData (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityLike {
+  if (!audience) audience = getAudience(byActor)
+
+  return audiencify(
+    {
+      type: 'Like' as 'Like',
+      id: url,
+      actor: byActor.url,
+      object: video.url
+    },
+    audience
+  )
 }
 
 // ---------------------------------------------------------------------------
 
 export {
-  sendLikeToOrigin,
-  sendLikeToVideoFollowers,
+  sendLike,
   likeActivityData
 }