]>
Commit | Line | Data |
---|---|---|
3fd3ab2d | 1 | import { ActivityAccept } from '../../../../shared/models/activitypub' |
50d6de9c C |
2 | import { ActorModel } from '../../../models/activitypub/actor' |
3 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | |
16f29007 | 4 | import { addFetchOutboxJob } from '../actor' |
1198edf4 | 5 | import { APProcessorOptions } from '../../../typings/activitypub-processor.model' |
5224c394 | 6 | import { SignatureActorModel } from '../../../typings/models' |
7a7724e6 | 7 | |
1198edf4 C |
8 | async function processAcceptActivity (options: APProcessorOptions<ActivityAccept>) { |
9 | const { byActor: targetActor, inboxActor } = options | |
50d6de9c | 10 | if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.') |
7a7724e6 | 11 | |
50d6de9c | 12 | return processAccept(inboxActor, targetActor) |
7a7724e6 C |
13 | } |
14 | ||
15 | // --------------------------------------------------------------------------- | |
16 | ||
17 | export { | |
18 | processAcceptActivity | |
19 | } | |
20 | ||
21 | // --------------------------------------------------------------------------- | |
22 | ||
5224c394 | 23 | async function processAccept (actor: ActorModel, targetActor: SignatureActorModel) { |
50d6de9c | 24 | const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id) |
7a7724e6 C |
25 | if (!follow) throw new Error('Cannot find associated follow.') |
26 | ||
7bc29171 C |
27 | if (follow.state !== 'accepted') { |
28 | follow.set('state', 'accepted') | |
29 | await follow.save() | |
f7cc67b4 | 30 | |
94a5ff8a | 31 | await addFetchOutboxJob(targetActor) |
7bc29171 | 32 | } |
7a7724e6 | 33 | } |