aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/lib/activitypub/process/process-accept.ts
blob: b9d906ec94c7afe65e9747509ae672e32e444753 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                                      

                                                                           
                                            
 

                                                                                          
 
                                                                
 
                                               









                                                                              

                                                                                      


                                                                
                     
                                                 
 
import { ActivityAccept } from '../../../../shared/models/activitypub'
import { ActorModel } from '../../../models/activitypub/actor'
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
import { addFetchOutboxJob } from '../fetch'

async function processAcceptActivity (activity: ActivityAccept, inboxActor?: ActorModel) {
  if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.')

  const targetActor = await ActorModel.loadByUrl(activity.actor)

  return processAccept(inboxActor, targetActor)
}

// ---------------------------------------------------------------------------

export {
  processAcceptActivity
}

// ---------------------------------------------------------------------------

async function processAccept (actor: ActorModel, targetActor: ActorModel) {
  const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id)
  if (!follow) throw new Error('Cannot find associated follow.')

  follow.set('state', 'accepted')
  await follow.save()
  await addFetchOutboxJob(targetActor, undefined)
}