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

                                                                               
                                            
 

                                                                                    
                                                                                    
 
                                               









                                                                              
                                                                                   
                                                                                      

                                                                
                                    
                             
                       
 
                                        
   
 
import { ActivityAccept } from '../../../../shared/models/activitypub'
import { ActorFollowModel } from '../../../models/actor/actor-follow'
import { APProcessorOptions } from '../../../types/activitypub-processor.model'
import { MActorDefault, MActorSignature } from '../../../types/models'
import { addFetchOutboxJob } from '../actor'

async function processAcceptActivity (options: APProcessorOptions<ActivityAccept>) {
  const { byActor: targetActor, inboxActor } = options
  if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.')

  return processAccept(inboxActor, targetActor)
}

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

export {
  processAcceptActivity
}

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

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

  if (follow.state !== 'accepted') {
    follow.state = 'accepted'
    await follow.save()

    await addFetchOutboxJob(targetActor)
  }
}