]>
Commit | Line | Data |
---|---|---|
1 | import { ActivityAccept } from '../../../../shared/models/activitypub' | |
2 | import { ActorModel } from '../../../models/activitypub/actor' | |
3 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | |
4 | import { addFetchOutboxJob } from '../actor' | |
5 | ||
6 | async function processAcceptActivity (activity: ActivityAccept, targetActor: ActorModel, inboxActor?: ActorModel) { | |
7 | if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.') | |
8 | ||
9 | return processAccept(inboxActor, targetActor) | |
10 | } | |
11 | ||
12 | // --------------------------------------------------------------------------- | |
13 | ||
14 | export { | |
15 | processAcceptActivity | |
16 | } | |
17 | ||
18 | // --------------------------------------------------------------------------- | |
19 | ||
20 | async function processAccept (actor: ActorModel, targetActor: ActorModel) { | |
21 | const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id) | |
22 | if (!follow) throw new Error('Cannot find associated follow.') | |
23 | ||
24 | if (follow.state !== 'accepted') { | |
25 | follow.set('state', 'accepted') | |
26 | await follow.save() | |
27 | await addFetchOutboxJob(targetActor) | |
28 | } | |
29 | } |