]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/send/send-like.ts
Add ability to list jobs
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-like.ts
CommitLineData
0032ebe9
C
1import { Transaction } from 'sequelize'
2import { 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
63c93323
C
17 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video)
18 const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
0032ebe9
C
19 const data = await likeActivityData(url, byAccount, video, audience)
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
63c93323 27 const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video)
4e50b6a1 28 const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
0032ebe9
C
29 const data = await likeActivityData(url, byAccount, video, audience)
30
63c93323 31 const toAccountsFollowers = await getAccountsInvolvedInVideo(video)
0032ebe9
C
32
33 const followersException = [ byAccount ]
63c93323 34 return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException)
0032ebe9
C
35}
36
37async function likeActivityData (url: string, byAccount: AccountInstance, video: VideoInstance, audience?: { to: string[], cc: string[] }) {
38 if (!audience) {
39 audience = await getAudience(byAccount)
40 }
41
42 const activity: ActivityLike = {
43 type: 'Like',
44 id: url,
45 actor: byAccount.url,
46 to: audience.to,
47 cc: audience.cc,
48 object: video.url
49 }
50
51 return activity
52}
53
54// ---------------------------------------------------------------------------
55
56export {
57 sendLikeToOrigin,
58 sendLikeToVideoFollowers,
59 likeActivityData
60}