]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/send/send-like.ts
Improve tests when waiting pending jobs
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-like.ts
CommitLineData
0032ebe9 1import { Transaction } from 'sequelize'
3fd3ab2d 2import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub'
50d6de9c 3import { ActorModel } from '../../../models/activitypub/actor'
3fd3ab2d 4import { VideoModel } from '../../../models/video/video'
0032ebe9 5import { getVideoLikeActivityPubUrl } from '../url'
e251f170
C
6import { broadcastToFollowers, unicastTo } from './utils'
7import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getVideoAudience } from '../audience'
0032ebe9 8
07197db4 9async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
50d6de9c 10 const url = getVideoLikeActivityPubUrl(byActor, video)
0032ebe9 11
50d6de9c 12 const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
0032ebe9 13
07197db4
C
14 // Send to origin
15 if (video.isOwned() === false) {
e251f170 16 const audience = getVideoAudience(video, accountsInvolvedInVideo)
2186386c 17 const data = likeActivityData(url, byActor, video, audience)
0032ebe9 18
07197db4
C
19 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
20 }
0032ebe9 21
07197db4 22 // Send to followers
4e50b6a1 23 const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
2186386c 24 const data = likeActivityData(url, byActor, video, audience)
0032ebe9 25
50d6de9c
C
26 const followersException = [ byActor ]
27 return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException)
0032ebe9
C
28}
29
2186386c
C
30function 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 )
0032ebe9
C
42}
43
44// ---------------------------------------------------------------------------
45
46export {
07197db4 47 sendLike,
0032ebe9
C
48 likeActivityData
49}