aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-reject.ts
blob: f06b03772d08c6135d9d6dc90ce42b209a54eb2c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { ActivityReject } from '../../../../shared/models/activitypub/activity'
import { getActorUrl } from '../../../helpers/activitypub'
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 actorUrl = getActorUrl(activity.actor)
  const targetActor = await ActorModel.loadByUrl(actorUrl)

  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
  })
}