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

28 lines
1015 B
TypeScript
Raw Normal View History

2017-11-13 16:39:41 +00:00
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)
2017-11-13 17:48:28 +00:00
return processAccept(inboxAccount, targetAccount)
2017-11-13 16:39:41 +00:00
}
// ---------------------------------------------------------------------------
export {
processAcceptActivity
}
// ---------------------------------------------------------------------------
2017-11-13 17:48:28 +00:00
async function processAccept (account: AccountInstance, targetAccount: AccountInstance) {
2017-11-13 16:39:41 +00: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 17:48:28 +00:00
await follow.save()
2017-11-13 16:39:41 +00:00
}