1
0
Fork 0
peertube/server/lib/activitypub/process/process-reject.ts
Chocobozzz 927fa4b11f
Add rejected state to follows
Prevent reprocessing already rejected follows
2022-07-27 13:52:13 +02:00

33 lines
1.2 KiB
TypeScript

import { ActivityReject } from '../../../../shared/models/activitypub/activity'
import { sequelizeTypescript } from '../../../initializers/database'
import { ActorFollowModel } from '../../../models/actor/actor-follow'
import { APProcessorOptions } from '../../../types/activitypub-processor.model'
import { MActor } from '../../../types/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: MActor, targetActor: MActor) {
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}.`)
actorFollow.state = 'rejected'
await actorFollow.save({ transaction: t })
return undefined
})
}