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