mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
Add reject processing for activitypub
This commit is contained in:
parent
cfe1efd200
commit
4bbc373f13
5 changed files with 55 additions and 3 deletions
32
server/lib/activitypub/process/process-reject.ts
Normal file
32
server/lib/activitypub/process/process-reject.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
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, inboxActor?: ActorModel) {
|
||||
if (inboxActor === undefined) throw new Error('Need to reject on explicit inbox.')
|
||||
|
||||
const targetActor = await ActorModel.loadByUrl(activity.actor)
|
||||
|
||||
return processReject(inboxActor, targetActor)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
processRejectActivity
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function processReject (actor: ActorModel, targetActor: ActorModel) {
|
||||
return sequelizeTypescript.transaction(async t => {
|
||||
const actorFollow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id, t)
|
||||
|
||||
if (!actorFollow) throw new Error(`'Unknown actor follow ${actor.id} -> ${targetActor.id}.`)
|
||||
|
||||
await actorFollow.destroy({ transaction: t })
|
||||
|
||||
return undefined
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue