1 import { ActivityAccept } from '../../../../shared/models/activitypub'
2 import { AccountModel } from '../../../models/account/account'
3 import { AccountFollowModel } from '../../../models/account/account-follow'
4 import { addFetchOutboxJob } from '../fetch'
6 async function processAcceptActivity (activity: ActivityAccept, inboxAccount?: AccountModel) {
7 if (inboxAccount === undefined) throw new Error('Need to accept on explicit inbox.')
9 const targetAccount = await AccountModel.loadByUrl(activity.actor)
11 return processAccept(inboxAccount, targetAccount)
14 // ---------------------------------------------------------------------------
20 // ---------------------------------------------------------------------------
22 async function processAccept (account: AccountModel, targetAccount: AccountModel) {
23 const follow = await AccountFollowModel.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)