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

33 lines
1.2 KiB
TypeScript
Raw Normal View History

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