]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/activitypub/send/send-follow.ts
51735ddfd0599569b4079c722b5cff27f2602f71
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-follow.ts
1 import { Transaction } from 'sequelize'
2 import { ActivityFollow } from '../../../../shared/models/activitypub'
3 import { AccountModel } from '../../../models/account/account'
4 import { AccountFollowModel } from '../../../models/account/account-follow'
5 import { getAccountFollowActivityPubUrl } from '../url'
6 import { unicastTo } from './misc'
7
8 function sendFollow (accountFollow: AccountFollowModel, t: Transaction) {
9 const me = accountFollow.AccountFollower
10 const following = accountFollow.AccountFollowing
11
12 const url = getAccountFollowActivityPubUrl(accountFollow)
13 const data = followActivityData(url, me, following)
14
15 return unicastTo(data, me, following.inboxUrl, t)
16 }
17
18 function followActivityData (url: string, byAccount: AccountModel, targetAccount: AccountModel): ActivityFollow {
19 return {
20 type: 'Follow',
21 id: url,
22 actor: byAccount.url,
23 object: targetAccount.url
24 }
25 }
26
27 // ---------------------------------------------------------------------------
28
29 export {
30 sendFollow,
31 followActivityData
32 }