X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Flib%2Factivitypub%2Fsend%2Fsend-like.ts;h=a5408ac6a2acbcd4975fb505b1da78eb49b0112f;hb=c48e82b5e0478434de30626d14594a97f2402e7c;hp=ddeb1fcd2e375bdc05fea4ebdaed0c6a3a3551cb;hpb=e251f170b00b2014ac4e823113c6ff40e3fb1471;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/send/send-like.ts b/server/lib/activitypub/send/send-like.ts index ddeb1fcd2..a5408ac6a 100644 --- a/server/lib/activitypub/send/send-like.ts +++ b/server/lib/activitypub/send/send-like.ts @@ -5,8 +5,11 @@ import { VideoModel } from '../../../models/video/video' import { getVideoLikeActivityPubUrl } from '../url' 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) @@ -14,41 +17,36 @@ async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) // Send to origin if (video.isOwned() === false) { const audience = getVideoAudience(video, accountsInvolvedInVideo) - const data = await likeActivityData(url, byActor, video, t, audience) + const data = buildLikeActivity(url, byActor, video, audience) return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl) } // Send to followers const audience = getObjectFollowersAudience(accountsInvolvedInVideo) - const data = await likeActivityData(url, byActor, video, t, audience) + const activity = buildLikeActivity(url, byActor, video, audience) const followersException = [ byActor ] - return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException) + return broadcastToFollowers(activity, byActor, accountsInvolvedInVideo, t, followersException) } -async function likeActivityData ( - url: string, - byActor: ActorModel, - video: VideoModel, - t: Transaction, - audience?: ActivityAudience -): Promise { - if (!audience) { - audience = await getAudience(byActor, t) - } - - return audiencify({ - type: 'Like' as 'Like', - id: url, - actor: byActor.url, - object: video.url - }, audience) +function buildLikeActivity (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 { sendLike, - likeActivityData + buildLikeActivity }