1 import { ActivityAccept } from '../../../../shared/models/activitypub/activity'
2 import { database as db } from '../../../initializers'
3 import { AccountInstance } from '../../../models/account/account-interface'
4 import { addFetchOutboxJob } from '../fetch'
6 async function processAcceptActivity (activity: ActivityAccept, inboxAccount?: AccountInstance) {
7 if (inboxAccount === undefined) throw new Error('Need to accept on explicit inbox.')
9 const targetAccount = await db.Account.loadByUrl(activity.actor)
11 return processAccept(inboxAccount, targetAccount)
14 // ---------------------------------------------------------------------------
20 // ---------------------------------------------------------------------------
22 async function processAccept (account: AccountInstance, targetAccount: AccountInstance) {
23 const follow = await db.AccountFollow.loadByAccountAndTarget(account.id, targetAccount.id)
24 if (!follow) throw new Error('Cannot find associated follow.')
26 follow.set('state', 'accepted')
28 await addFetchOutboxJob(targetAccount, undefined)