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