2017-12-12 10:53:50 -06:00
|
|
|
import { ActivityAccept } from '../../../../shared/models/activitypub'
|
|
|
|
import { AccountModel } from '../../../models/account/account'
|
|
|
|
import { AccountFollowModel } from '../../../models/account/account-follow'
|
2017-11-22 04:27:40 -06:00
|
|
|
import { addFetchOutboxJob } from '../fetch'
|
2017-11-13 10:39:41 -06:00
|
|
|
|
2017-12-12 10:53:50 -06:00
|
|
|
async function processAcceptActivity (activity: ActivityAccept, inboxAccount?: AccountModel) {
|
2017-11-13 10:39:41 -06:00
|
|
|
if (inboxAccount === undefined) throw new Error('Need to accept on explicit inbox.')
|
|
|
|
|
2017-12-12 10:53:50 -06:00
|
|
|
const targetAccount = await AccountModel.loadByUrl(activity.actor)
|
2017-11-13 10:39:41 -06:00
|
|
|
|
2017-11-13 11:48:28 -06:00
|
|
|
return processAccept(inboxAccount, targetAccount)
|
2017-11-13 10:39:41 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
processAcceptActivity
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-12-12 10:53:50 -06:00
|
|
|
async function processAccept (account: AccountModel, targetAccount: AccountModel) {
|
|
|
|
const follow = await AccountFollowModel.loadByAccountAndTarget(account.id, targetAccount.id)
|
2017-11-13 10:39:41 -06:00
|
|
|
if (!follow) throw new Error('Cannot find associated follow.')
|
|
|
|
|
|
|
|
follow.set('state', 'accepted')
|
2017-11-13 11:48:28 -06:00
|
|
|
await follow.save()
|
2017-11-22 04:27:40 -06:00
|
|
|
await addFetchOutboxJob(targetAccount, undefined)
|
2017-11-13 10:39:41 -06:00
|
|
|
}
|