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

30 lines
1.1 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'
import { addFetchOutboxJob } from '../fetch'
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()
await addFetchOutboxJob(targetAccount, undefined)
2017-11-13 17:39:41 +01:00
}