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

                                                                               
                                                                           
                                                                                 
                                                        
 

                                                                                    

                                                                                    










                                                                              
                                                                                      
                                                     
                                                                                                   
 
                                                                                                   





                                                 
import { ActivityReject } from '../../../../shared/models/activitypub/activity'
import { sequelizeTypescript } from '../../../initializers'
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
import { ActorModelOnly } from '../../../typings/models'

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

  return processReject(inboxActor, targetActor)
}

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

export {
  processRejectActivity
}

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

async function processReject (follower: ActorModelOnly, targetActor: ActorModelOnly) {
  return sequelizeTypescript.transaction(async t => {
    const actorFollow = await ActorFollowModel.loadByActorAndTarget(follower.id, targetActor.id, t)

    if (!actorFollow) throw new Error(`'Unknown actor follow ${follower.id} -> ${targetActor.id}.`)

    await actorFollow.destroy({ transaction: t })

    return undefined
  })
}