]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/send/send-like.ts
Split files in activitypub server
[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)
07197db4 17 const data = await likeActivityData(url, byActor, video, t, 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)
50d6de9c 24 const data = await likeActivityData(url, byActor, video, t, audience)
0032ebe9 25
50d6de9c
C
26 const followersException = [ byActor ]
27 return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException)
0032ebe9
C
28}
29
25ed141c
C
30async function likeActivityData (
31 url: string,
50d6de9c 32 byActor: ActorModel,
3fd3ab2d 33 video: VideoModel,
25ed141c
C
34 t: Transaction,
35 audience?: ActivityAudience
3fd3ab2d 36): Promise<ActivityLike> {
0032ebe9 37 if (!audience) {
50d6de9c 38 audience = await getAudience(byActor, t)
0032ebe9
C
39 }
40
e12a0092 41 return audiencify({
73c08093 42 type: 'Like' as 'Like',
0032ebe9 43 id: url,
50d6de9c 44 actor: byActor.url,
0032ebe9 45 object: video.url
e12a0092 46 }, audience)
0032ebe9
C
47}
48
49// ---------------------------------------------------------------------------
50
51export {
07197db4 52 sendLike,
0032ebe9
C
53 likeActivityData
54}