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