PeerTube/server/core/lib/activitypub/process/process-accept.ts

33 lines
1.2 KiB
TypeScript
Raw Normal View History

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