]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/process/process-accept.ts
Add context on activitypub responses
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-accept.ts
CommitLineData
3fd3ab2d 1import { ActivityAccept } from '../../../../shared/models/activitypub'
50d6de9c
C
2import { ActorModel } from '../../../models/activitypub/actor'
3import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
c46edbc2 4import { addFetchOutboxJob } from '../fetch'
7a7724e6 5
50d6de9c
C
6async function processAcceptActivity (activity: ActivityAccept, inboxActor?: ActorModel) {
7 if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.')
7a7724e6 8
50d6de9c 9 const targetActor = await ActorModel.loadByUrl(activity.actor)
7a7724e6 10
50d6de9c 11 return processAccept(inboxActor, targetActor)
7a7724e6
C
12}
13
14// ---------------------------------------------------------------------------
15
16export {
17 processAcceptActivity
18}
19
20// ---------------------------------------------------------------------------
21
50d6de9c
C
22async function processAccept (actor: ActorModel, targetActor: ActorModel) {
23 const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id)
7a7724e6
C
24 if (!follow) throw new Error('Cannot find associated follow.')
25
7bc29171
C
26 if (follow.state !== 'accepted') {
27 follow.set('state', 'accepted')
28 await follow.save()
94a5ff8a 29 await addFetchOutboxJob(targetActor)
7bc29171 30 }
7a7724e6 31}