Fix player play exception on chromium
[oweals/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 '../fetch'
5
6 async function processAcceptActivity (activity: ActivityAccept, inboxActor?: ActorModel) {
7   if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.')
8
9   const targetActor = await ActorModel.loadByUrl(activity.actor)
10
11   return processAccept(inboxActor, targetActor)
12 }
13
14 // ---------------------------------------------------------------------------
15
16 export {
17   processAcceptActivity
18 }
19
20 // ---------------------------------------------------------------------------
21
22 async function processAccept (actor: ActorModel, targetActor: ActorModel) {
23   const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id)
24   if (!follow) throw new Error('Cannot find associated follow.')
25
26   follow.set('state', 'accepted')
27   await follow.save()
28   await addFetchOutboxJob(targetActor, undefined)
29 }