1 import { Transaction } from 'sequelize'
2 import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub'
3 import { ActorModel } from '../../../models/activitypub/actor'
4 import { VideoModel } from '../../../models/video/video'
5 import { getVideoLikeActivityPubUrl } from '../url'
6 import { broadcastToFollowers, unicastTo } from './utils'
7 import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getVideoAudience } from '../audience'
8 import { logger } from '../../../helpers/logger'
10 async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
11 logger.info('Creating job to like %s.', video.url)
13 const url = getVideoLikeActivityPubUrl(byActor, video)
15 const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
18 if (video.isOwned() === false) {
19 const audience = getVideoAudience(video, accountsInvolvedInVideo)
20 const data = likeActivityData(url, byActor, video, audience)
22 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
26 const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
27 const data = likeActivityData(url, byActor, video, audience)
29 const followersException = [ byActor ]
30 return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException)
33 function likeActivityData (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityLike {
34 if (!audience) audience = getAudience(byActor)
38 type: 'Like' as 'Like',
47 // ---------------------------------------------------------------------------