]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/send/send-like.ts
Misc cleanup
[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'
3import { getServerAccount } from '../../../helpers/utils'
4import { AccountInstance, VideoInstance } from '../../../models'
5import { getVideoLikeActivityPubUrl } from '../url'
6import {
7 broadcastToFollowers,
8 getAccountsToForwardVideoAction,
9 getAudience,
10 getOriginVideoAudience,
11 getVideoFollowersAudience,
12 unicastTo
13} from './misc'
14
15async function sendLikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
16 const url = getVideoLikeActivityPubUrl(byAccount, video)
17
18 const audience = getOriginVideoAudience(video)
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
27 const audience = getVideoFollowersAudience(video)
28 const data = await likeActivityData(url, byAccount, video, audience)
29
30 const accountsToForwardView = await getAccountsToForwardVideoAction(byAccount, video)
31 const serverAccount = await getServerAccount()
32
33 const followersException = [ byAccount ]
34 return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException)
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}