]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/activitypub/send/send-follow.ts
Improve AP validation for Notes
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-follow.ts
1 import { ActivityFollow } from '../../../../shared/models/activitypub'
2 import { ActorModel } from '../../../models/activitypub/actor'
3 import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
4 import { getActorFollowActivityPubUrl } from '../url'
5 import { unicastTo } from './misc'
6
7 function sendFollow (actorFollow: ActorFollowModel) {
8 const me = actorFollow.ActorFollower
9 const following = actorFollow.ActorFollowing
10
11 const url = getActorFollowActivityPubUrl(actorFollow)
12 const data = followActivityData(url, me, following)
13
14 return unicastTo(data, me, following.inboxUrl)
15 }
16
17 function followActivityData (url: string, byActor: ActorModel, targetActor: ActorModel): ActivityFollow {
18 return {
19 type: 'Follow',
20 id: url,
21 actor: byActor.url,
22 object: targetActor.url
23 }
24 }
25
26 // ---------------------------------------------------------------------------
27
28 export {
29 sendFollow,
30 followActivityData
31 }