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'
9 async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
10 const url = getVideoLikeActivityPubUrl(byActor, video)
12 const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
15 if (video.isOwned() === false) {
16 const audience = getVideoAudience(video, accountsInvolvedInVideo)
17 const data = likeActivityData(url, byActor, video, audience)
19 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
23 const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
24 const data = likeActivityData(url, byActor, video, audience)
26 const followersException = [ byActor ]
27 return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException)
30 function likeActivityData (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityLike {
31 if (!audience) audience = getAudience(byActor)
35 type: 'Like' as 'Like',
44 // ---------------------------------------------------------------------------