1
0
Fork 0
peertube/server/lib/activitypub/process/process-reject.ts

33 lines
1.2 KiB
TypeScript
Raw Normal View History

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