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