aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/lib/activitypub/process/process-accept.ts
blob: 5b321f771d348aa4d3c9727c036769b209972ba1 (plain) (tree)
1
2
3
4
5
6
7
8
9


                                                                           
                                            
 
                                                                                              

                                                                                      
                                                                    
 
                                                   









                                                                              

                                                                                              


                                                                
                     
                                                   
 
import { ActivityAccept } from '../../../../shared/models/activitypub'
import { AccountModel } from '../../../models/account/account'
import { AccountFollowModel } from '../../../models/account/account-follow'
import { addFetchOutboxJob } from '../fetch'

async function processAcceptActivity (activity: ActivityAccept, inboxAccount?: AccountModel) {
  if (inboxAccount === undefined) throw new Error('Need to accept on explicit inbox.')

  const targetAccount = await AccountModel.loadByUrl(activity.actor)

  return processAccept(inboxAccount, targetAccount)
}

// ---------------------------------------------------------------------------

export {
  processAcceptActivity
}

// ---------------------------------------------------------------------------

async function processAccept (account: AccountModel, targetAccount: AccountModel) {
  const follow = await AccountFollowModel.loadByAccountAndTarget(account.id, targetAccount.id)
  if (!follow) throw new Error('Cannot find associated follow.')

  follow.set('state', 'accepted')
  await follow.save()
  await addFetchOutboxJob(targetAccount, undefined)
}