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