]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/process/process-accept.ts
Stronger model typings
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-accept.ts
CommitLineData
3fd3ab2d 1import { ActivityAccept } from '../../../../shared/models/activitypub'
50d6de9c 2import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
16f29007 3import { addFetchOutboxJob } from '../actor'
1198edf4 4import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
453e83ea 5import { MActorDefault, MActorSignature } from '../../../typings/models'
7a7724e6 6
1198edf4
C
7async function processAcceptActivity (options: APProcessorOptions<ActivityAccept>) {
8 const { byActor: targetActor, inboxActor } = options
50d6de9c 9 if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.')
7a7724e6 10
50d6de9c 11 return processAccept(inboxActor, targetActor)
7a7724e6
C
12}
13
14// ---------------------------------------------------------------------------
15
16export {
17 processAcceptActivity
18}
19
20// ---------------------------------------------------------------------------
21
453e83ea 22async function processAccept (actor: MActorDefault, targetActor: MActorSignature) {
50d6de9c 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()
f7cc67b4 29
94a5ff8a 30 await addFetchOutboxJob(targetActor)
7bc29171 31 }
7a7724e6 32}