aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process-accept.ts
blob: 9e0cd4032df31dccd63c4dbd0ff11b432954be9d (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
import { ActivityAccept } from '../../../shared/models/activitypub/activity'
import { database as db } from '../../initializers'
import { AccountInstance } from '../../models/account/account-interface'

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

  const targetAccount = await db.Account.loadByUrl(activity.actor)

  return processAccept(inboxAccount, targetAccount)
}

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

export {
  processAcceptActivity
}

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

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

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