1
0
Fork 0
peertube/server/lib/activitypub/process/process-accept.ts
2017-11-27 19:40:52 +01:00

27 lines
1 KiB
TypeScript

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()
}