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