2017-12-12 10:53:50 -06:00
|
|
|
import { ActivityAccept } from '../../../../shared/models/activitypub'
|
2017-12-14 10:38:41 -06:00
|
|
|
import { ActorModel } from '../../../models/activitypub/actor'
|
|
|
|
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
2018-05-25 04:17:41 -05:00
|
|
|
import { addFetchOutboxJob } from '../actor'
|
2019-08-02 03:53:36 -05:00
|
|
|
import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
|
2019-08-09 01:17:16 -05:00
|
|
|
import { SignatureActorModel } from '../../../typings/models'
|
2017-11-13 10:39:41 -06:00
|
|
|
|
2019-08-02 03:53:36 -05:00
|
|
|
async function processAcceptActivity (options: APProcessorOptions<ActivityAccept>) {
|
|
|
|
const { byActor: targetActor, inboxActor } = options
|
2017-12-14 10:38:41 -06:00
|
|
|
if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.')
|
2017-11-13 10:39:41 -06:00
|
|
|
|
2017-12-14 10:38:41 -06:00
|
|
|
return processAccept(inboxActor, targetActor)
|
2017-11-13 10:39:41 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
processAcceptActivity
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2019-08-09 01:17:16 -05:00
|
|
|
async function processAccept (actor: ActorModel, targetActor: SignatureActorModel) {
|
2017-12-14 10:38:41 -06:00
|
|
|
const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id)
|
2017-11-13 10:39:41 -06:00
|
|
|
if (!follow) throw new Error('Cannot find associated follow.')
|
|
|
|
|
2018-01-11 04:40:18 -06:00
|
|
|
if (follow.state !== 'accepted') {
|
|
|
|
follow.set('state', 'accepted')
|
|
|
|
await follow.save()
|
2019-01-04 01:56:20 -06:00
|
|
|
|
2018-01-25 08:05:18 -06:00
|
|
|
await addFetchOutboxJob(targetActor)
|
2018-01-11 04:40:18 -06:00
|
|
|
}
|
2017-11-13 10:39:41 -06:00
|
|
|
}
|