aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-accept.ts
blob: 5b321f771d348aa4d3c9727c036769b209972ba1 (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
import { ActivityAccept } from '../../../../shared/models/activitypub'
import { AccountModel } from '../../../models/account/account'
import { AccountFollowModel } from '../../../models/account/account-follow'
import { addFetchOutboxJob } from '../fetch'

async function processAcceptActivity (activity: ActivityAccept, inboxAccount?: AccountModel) {
  if (inboxAccount === undefined) throw new Error('Need to accept on explicit inbox.')

  const targetAccount = await AccountModel.loadByUrl(activity.actor)

  return processAccept(inboxAccount, targetAccount)
}

// ---------------------------------------------------------------------------

export {
  processAcceptActivity
}

// ---------------------------------------------------------------------------

async function processAccept (account: AccountModel, targetAccount: AccountModel) {
  const follow = await AccountFollowModel.loadByAccountAndTarget(account.id, targetAccount.id)
  if (!follow) throw new Error('Cannot find associated follow.')

  follow.set('state', 'accepted')
  await follow.save()
  await addFetchOutboxJob(targetAccount, undefined)
}