]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/activitypub/process/process-accept.ts
5b321f771d348aa4d3c9727c036769b209972ba1
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-accept.ts
1 import { ActivityAccept } from '../../../../shared/models/activitypub'
2 import { AccountModel } from '../../../models/account/account'
3 import { AccountFollowModel } from '../../../models/account/account-follow'
4 import { addFetchOutboxJob } from '../fetch'
5
6 async function processAcceptActivity (activity: ActivityAccept, inboxAccount?: AccountModel) {
7 if (inboxAccount === undefined) throw new Error('Need to accept on explicit inbox.')
8
9 const targetAccount = await AccountModel.loadByUrl(activity.actor)
10
11 return processAccept(inboxAccount, targetAccount)
12 }
13
14 // ---------------------------------------------------------------------------
15
16 export {
17 processAcceptActivity
18 }
19
20 // ---------------------------------------------------------------------------
21
22 async function processAccept (account: AccountModel, targetAccount: AccountModel) {
23 const follow = await AccountFollowModel.loadByAccountAndTarget(account.id, targetAccount.id)
24 if (!follow) throw new Error('Cannot find associated follow.')
25
26 follow.set('state', 'accepted')
27 await follow.save()
28 await addFetchOutboxJob(targetAccount, undefined)
29 }