1
0
Fork 0
peertube/server/lib/activitypub/process/process-accept.ts

30 lines
1.1 KiB
TypeScript
Raw Normal View History

2017-12-12 11:53:50 -05: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 11:39:41 -05:00
2017-12-12 11:53:50 -05:00
async function processAcceptActivity (activity: ActivityAccept, inboxAccount?: AccountModel) {
2017-11-13 11:39:41 -05:00
if (inboxAccount === undefined) throw new Error('Need to accept on explicit inbox.')
2017-12-12 11:53:50 -05:00
const targetAccount = await AccountModel.loadByUrl(activity.actor)
2017-11-13 11:39:41 -05:00
2017-11-13 12:48:28 -05:00
return processAccept(inboxAccount, targetAccount)
2017-11-13 11:39:41 -05:00
}
// ---------------------------------------------------------------------------
export {
processAcceptActivity
}
// ---------------------------------------------------------------------------
2017-12-12 11:53:50 -05:00
async function processAccept (account: AccountModel, targetAccount: AccountModel) {
const follow = await AccountFollowModel.loadByAccountAndTarget(account.id, targetAccount.id)
2017-11-13 11:39:41 -05:00
if (!follow) throw new Error('Cannot find associated follow.')
follow.set('state', 'accepted')
2017-11-13 12:48:28 -05:00
await follow.save()
await addFetchOutboxJob(targetAccount, undefined)
2017-11-13 11:39:41 -05:00
}