X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fsend%2Fsend-like.ts;h=83225f5df1d62186561e40a43953815d35773c13;hb=8e0fd45e14993793c64e06682a4a05c29068d398;hp=78ed1aaf284774a92f4ac32e8ec951928f8a7d38;hpb=94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/send/send-like.ts b/server/lib/activitypub/send/send-like.ts index 78ed1aaf2..83225f5df 100644 --- a/server/lib/activitypub/send/send-like.ts +++ b/server/lib/activitypub/send/send-like.ts @@ -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 { - 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 }