]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/send/send-like.ts
Add more info logging
[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'
8e0fd45e 8import { logger } from '../../../helpers/logger'
0032ebe9 9
07197db4 10async function sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
8e0fd45e
C
11 logger.info('Creating job to like %s.', video.url)
12
50d6de9c 13 const url = getVideoLikeActivityPubUrl(byActor, video)
0032ebe9 14
50d6de9c 15 const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
0032ebe9 16
07197db4
C
17 // Send to origin
18 if (video.isOwned() === false) {
e251f170 19 const audience = getVideoAudience(video, accountsInvolvedInVideo)
2186386c 20 const data = likeActivityData(url, byActor, video, audience)
0032ebe9 21
07197db4
C
22 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
23 }
0032ebe9 24
07197db4 25 // Send to followers
4e50b6a1 26 const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
2186386c 27 const data = likeActivityData(url, byActor, video, audience)
0032ebe9 28
50d6de9c
C
29 const followersException = [ byActor ]
30 return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException)
0032ebe9
C
31}
32
2186386c
C
33function likeActivityData (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityLike {
34 if (!audience) audience = getAudience(byActor)
35
36 return audiencify(
37 {
38 type: 'Like' as 'Like',
39 id: url,
40 actor: byActor.url,
41 object: video.url
42 },
43 audience
44 )
0032ebe9
C
45}
46
47// ---------------------------------------------------------------------------
48
49export {
07197db4 50 sendLike,
0032ebe9
C
51 likeActivityData
52}