]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/send/send-like.ts
Fix preview 404
[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
C
5import { getVideoLikeActivityPubUrl } from '../url'
6import {
e12a0092 7 audiencify,
0032ebe9 8 broadcastToFollowers,
50d6de9c 9 getActorsInvolvedInVideo,
0032ebe9 10 getAudience,
4e50b6a1 11 getObjectFollowersAudience,
50d6de9c 12 getOriginVideoAudience,
0032ebe9
C
13 unicastTo
14} from './misc'
15
50d6de9c
C
16async function sendLikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
17 const url = getVideoLikeActivityPubUrl(byActor, video)
0032ebe9 18
50d6de9c 19 const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
63c93323 20 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
50d6de9c 21 const data = await likeActivityData(url, byActor, video, t, audience)
0032ebe9 22
50d6de9c 23 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t)
0032ebe9
C
24}
25
50d6de9c
C
26async function sendLikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
27 const url = getVideoLikeActivityPubUrl(byActor, video)
0032ebe9 28
50d6de9c 29 const accountsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
4e50b6a1 30 const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
50d6de9c 31 const data = await likeActivityData(url, byActor, video, t, audience)
0032ebe9 32
50d6de9c
C
33 const followersException = [ byActor ]
34 return broadcastToFollowers(data, byActor, accountsInvolvedInVideo, t, followersException)
0032ebe9
C
35}
36
25ed141c
C
37async function likeActivityData (
38 url: string,
50d6de9c 39 byActor: ActorModel,
3fd3ab2d 40 video: VideoModel,
25ed141c
C
41 t: Transaction,
42 audience?: ActivityAudience
3fd3ab2d 43): Promise<ActivityLike> {
0032ebe9 44 if (!audience) {
50d6de9c 45 audience = await getAudience(byActor, t)
0032ebe9
C
46 }
47
e12a0092 48 return audiencify({
0032ebe9
C
49 type: 'Like',
50 id: url,
50d6de9c 51 actor: byActor.url,
0032ebe9 52 object: video.url
e12a0092 53 }, audience)
0032ebe9
C
54}
55
56// ---------------------------------------------------------------------------
57
58export {
59 sendLikeToOrigin,
60 sendLikeToVideoFollowers,
61 likeActivityData
62}