]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/activitypub/send/send-accept.ts
Split files in activitypub server
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-accept.ts
1 import { ActivityAccept, ActivityFollow } from '../../../../shared/models/activitypub'
2 import { ActorModel } from '../../../models/activitypub/actor'
3 import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
4 import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url'
5 import { unicastTo } from './utils'
6 import { followActivityData } from './send-follow'
7
8 async function sendAccept (actorFollow: ActorFollowModel) {
9 const follower = actorFollow.ActorFollower
10 const me = actorFollow.ActorFollowing
11
12 const followUrl = getActorFollowActivityPubUrl(actorFollow)
13 const followData = followActivityData(followUrl, follower, me)
14
15 const url = getActorFollowAcceptActivityPubUrl(actorFollow)
16 const data = acceptActivityData(url, me, followData)
17
18 return unicastTo(data, me, follower.inboxUrl)
19 }
20
21 // ---------------------------------------------------------------------------
22
23 export {
24 sendAccept
25 }
26
27 // ---------------------------------------------------------------------------
28
29 function acceptActivityData (url: string, byActor: ActorModel, followActivityData: ActivityFollow): ActivityAccept {
30 return {
31 type: 'Accept',
32 id: url,
33 actor: byActor.url,
34 object: followActivityData
35 }
36 }