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