process-reject.ts 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import { ActivityReject } from '../../../../shared/models/activitypub/activity'
  2. import { sequelizeTypescript } from '../../../initializers'
  3. import { ActorModel } from '../../../models/activitypub/actor'
  4. import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
  5. async function processRejectActivity (activity: ActivityReject, targetActor: ActorModel, inboxActor?: ActorModel) {
  6. if (inboxActor === undefined) throw new Error('Need to reject on explicit inbox.')
  7. return processReject(inboxActor, targetActor)
  8. }
  9. // ---------------------------------------------------------------------------
  10. export {
  11. processRejectActivity
  12. }
  13. // ---------------------------------------------------------------------------
  14. async function processReject (follower: ActorModel, targetActor: ActorModel) {
  15. return sequelizeTypescript.transaction(async t => {
  16. const actorFollow = await ActorFollowModel.loadByActorAndTarget(follower.id, targetActor.id, t)
  17. if (!actorFollow) throw new Error(`'Unknown actor follow ${follower.id} -> ${targetActor.id}.`)
  18. await actorFollow.destroy({ transaction: t })
  19. return undefined
  20. })
  21. }