PeerTube/server/lib/activitypub/process/process-reject.ts

33 lines
1.2 KiB
TypeScript
Raw Normal View History

2018-01-11 17:37:49 +01:00
import { ActivityReject } from '../../../../shared/models/activitypub/activity'
2020-05-07 14:58:24 +02:00
import { sequelizeTypescript } from '../../../initializers/database'
2021-05-11 11:15:29 +02:00
import { ActorFollowModel } from '../../../models/actor/actor-follow'
2020-06-18 10:45:25 +02:00
import { APProcessorOptions } from '../../../types/activitypub-processor.model'
import { MActor } from '../../../types/models'
2018-01-11 17:37:49 +01:00
2019-08-02 10:53:36 +02:00
async function processRejectActivity (options: APProcessorOptions<ActivityReject>) {
const { byActor: targetActor, inboxActor } = options
2018-01-11 17:37:49 +01:00
if (inboxActor === undefined) throw new Error('Need to reject on explicit inbox.')
return processReject(inboxActor, targetActor)
}
// ---------------------------------------------------------------------------
export {
processRejectActivity
}
// ---------------------------------------------------------------------------
2019-08-15 11:53:26 +02:00
async function processReject (follower: MActor, targetActor: MActor) {
2018-01-11 17:37:49 +01:00
return sequelizeTypescript.transaction(async t => {
2018-09-19 15:47:55 +02:00
const actorFollow = await ActorFollowModel.loadByActorAndTarget(follower.id, targetActor.id, t)
2018-01-11 17:37:49 +01:00
2018-09-19 15:47:55 +02:00
if (!actorFollow) throw new Error(`'Unknown actor follow ${follower.id} -> ${targetActor.id}.`)
2018-01-11 17:37:49 +01:00
await actorFollow.destroy({ transaction: t })
return undefined
})
}