Begin moving video channel to actor
[oweals/peertube.git] / server / lib / activitypub / send / send-accept.ts
1 import { Transaction } from 'sequelize'
2 import { ActivityAccept } from '../../../../shared/models/activitypub'
3 import { ActorModel } from '../../../models/activitypub/actor'
4 import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
5 import { getActorFollowAcceptActivityPubUrl } from '../url'
6 import { unicastTo } from './misc'
7
8 async function sendAccept (actorFollow: ActorFollowModel, t: Transaction) {
9   const follower = actorFollow.ActorFollower
10   const me = actorFollow.ActorFollowing
11
12   const url = getActorFollowAcceptActivityPubUrl(actorFollow)
13   const data = acceptActivityData(url, me)
14
15   return unicastTo(data, me, follower.inboxUrl, t)
16 }
17
18 // ---------------------------------------------------------------------------
19
20 export {
21   sendAccept
22 }
23
24 // ---------------------------------------------------------------------------
25
26 function acceptActivityData (url: string, byActor: ActorModel): ActivityAccept {
27   return {
28     type: 'Accept',
29     id: url,
30     actor: byActor.url
31   }
32 }