]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/activitypub/send/send-like.ts
Improve tests when waiting pending jobs
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-like.ts
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
9 async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
10 const url = getVideoLikeActivityPubUrl(byActor, video)
11
12 const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
13
14 // Send to origin
15 if (video.isOwned() === false) {
16 const audience = getVideoAudience(video, accountsInvolvedInVideo)
17 const data = likeActivityData(url, byActor, video, audience)
18
19 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
20 }
21
22 // Send to followers
23 const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
24 const data = likeActivityData(url, byActor, video, audience)
25
26 const followersException = [ byActor ]
27 return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException)
28 }
29
30 function likeActivityData (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityLike {
31 if (!audience) audience = getAudience(byActor)
32
33 return audiencify(
34 {
35 type: 'Like' as 'Like',
36 id: url,
37 actor: byActor.url,
38 object: video.url
39 },
40 audience
41 )
42 }
43
44 // ---------------------------------------------------------------------------
45
46 export {
47 sendLike,
48 likeActivityData
49 }