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

30 lines
1.1 KiB
TypeScript
Raw Normal View History

2017-11-20 02:43:39 -06:00
import { ActivityAccept } from '../../../../shared/models/activitypub/activity'
import { database as db } from '../../../initializers'
import { AccountInstance } from '../../../models/account/account-interface'
import { addFetchOutboxJob } from '../fetch'
2017-11-13 10:39:41 -06: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 11:48:28 -06:00
return processAccept(inboxAccount, targetAccount)
2017-11-13 10:39:41 -06:00
}
// ---------------------------------------------------------------------------
export {
processAcceptActivity
}
// ---------------------------------------------------------------------------
2017-11-13 11:48:28 -06:00
async function processAccept (account: AccountInstance, targetAccount: AccountInstance) {
2017-11-13 10:39:41 -06: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 11:48:28 -06:00
await follow.save()
await addFetchOutboxJob(targetAccount, undefined)
2017-11-13 10:39:41 -06:00
}