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