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

31 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-01-11 17:37:49 +01: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'
async function processRejectActivity (activity: ActivityReject, targetActor: ActorModel, inboxActor?: ActorModel) {
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
}
// ---------------------------------------------------------------------------
2018-09-19 15:47:55 +02:00
async function processReject (follower: ActorModel, targetActor: ActorModel) {
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
})
}