]>
Commit | Line | Data |
---|---|---|
3fd3ab2d | 1 | import { ActivityAccept } from '../../../../shared/models/activitypub' |
50d6de9c | 2 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
16f29007 | 3 | import { addFetchOutboxJob } from '../actor' |
1198edf4 | 4 | import { APProcessorOptions } from '../../../typings/activitypub-processor.model' |
453e83ea | 5 | import { MActorDefault, MActorSignature } from '../../../typings/models' |
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 C |
26 | if (follow.state !== 'accepted') { |
27 | follow.set('state', 'accepted') | |
28 | await follow.save() | |
f7cc67b4 | 29 | |
94a5ff8a | 30 | await addFetchOutboxJob(targetActor) |
7bc29171 | 31 | } |
7a7724e6 | 32 | } |