]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/lib/activitypub/process/process-accept.ts
Lazy load avatars
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-accept.ts
... / ...
CommitLineData
1import { ActivityAccept } from '../../../../shared/models/activitypub'
2import { ActorModel } from '../../../models/activitypub/actor'
3import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
4import { addFetchOutboxJob } from '../actor'
5import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
6import { SignatureActorModel } from '../../../typings/models'
7
8async function processAcceptActivity (options: APProcessorOptions<ActivityAccept>) {
9 const { byActor: targetActor, inboxActor } = options
10 if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.')
11
12 return processAccept(inboxActor, targetActor)
13}
14
15// ---------------------------------------------------------------------------
16
17export {
18 processAcceptActivity
19}
20
21// ---------------------------------------------------------------------------
22
23async function processAccept (actor: ActorModel, targetActor: SignatureActorModel) {
24 const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id)
25 if (!follow) throw new Error('Cannot find associated follow.')
26
27 if (follow.state !== 'accepted') {
28 follow.set('state', 'accepted')
29 await follow.save()
30
31 await addFetchOutboxJob(targetActor)
32 }
33}