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

30 lines
1.1 KiB
TypeScript
Raw Normal View History

2017-12-12 17:53:50 +01:00
import { ActivityAccept } from '../../../../shared/models/activitypub'
import { AccountModel } from '../../../models/account/account'
import { AccountFollowModel } from '../../../models/account/account-follow'
import { addFetchOutboxJob } from '../fetch'
2017-11-13 17:39:41 +01:00
2017-12-12 17:53:50 +01:00
async function processAcceptActivity (activity: ActivityAccept, inboxAccount?: AccountModel) {
2017-11-13 17:39:41 +01:00
if (inboxAccount === undefined) throw new Error('Need to accept on explicit inbox.')
2017-12-12 17:53:50 +01:00
const targetAccount = await AccountModel.loadByUrl(activity.actor)
2017-11-13 17:39:41 +01:00
2017-11-13 18:48:28 +01:00
return processAccept(inboxAccount, targetAccount)
2017-11-13 17:39:41 +01:00
}
// ---------------------------------------------------------------------------
export {
processAcceptActivity
}
// ---------------------------------------------------------------------------
2017-12-12 17:53:50 +01:00
async function processAccept (account: AccountModel, targetAccount: AccountModel) {
const follow = await AccountFollowModel.loadByAccountAndTarget(account.id, targetAccount.id)
2017-11-13 17:39:41 +01:00
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
}