PeerTube/server/lib/activitypub/process/process-accept.ts

28 lines
1.0 KiB
TypeScript
Raw Normal View History

2017-11-20 09:43:39 +01:00
import { ActivityAccept } from '../../../../shared/models/activitypub/activity'
import { database as db } from '../../../initializers'
import { AccountInstance } from '../../../models/account/account-interface'
2017-11-13 17:39:41 +01:00
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)
2017-11-13 18:48:28 +01:00
return processAccept(inboxAccount, targetAccount)
2017-11-13 17:39:41 +01:00
}
// ---------------------------------------------------------------------------
export {
processAcceptActivity
}
// ---------------------------------------------------------------------------
2017-11-13 18:48:28 +01:00
async function processAccept (account: AccountInstance, targetAccount: AccountInstance) {
2017-11-13 17:39:41 +01:00
const follow = await db.AccountFollow.loadByAccountAndTarget(account.id, targetAccount.id)
if (!follow) throw new Error('Cannot find associated follow.')
follow.set('state', 'accepted')
2017-11-13 18:48:28 +01:00
await follow.save()
2017-11-13 17:39:41 +01:00
}