]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/lib/activitypub/process/process-accept.ts
Add ability to search video channels
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-accept.ts
... / ...
CommitLineData
1import { ActivityAccept } from '../../../../shared/models/activitypub'
2import { getActorUrl } from '../../../helpers/activitypub'
3import { ActorModel } from '../../../models/activitypub/actor'
4import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
5import { addFetchOutboxJob } from '../actor'
6
7async function processAcceptActivity (activity: ActivityAccept, inboxActor?: ActorModel) {
8 if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.')
9
10 const actorUrl = getActorUrl(activity.actor)
11 const targetActor = await ActorModel.loadByUrl(actorUrl)
12
13 return processAccept(inboxActor, targetActor)
14}
15
16// ---------------------------------------------------------------------------
17
18export {
19 processAcceptActivity
20}
21
22// ---------------------------------------------------------------------------
23
24async function processAccept (actor: ActorModel, targetActor: ActorModel) {
25 const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id)
26 if (!follow) throw new Error('Cannot find associated follow.')
27
28 if (follow.state !== 'accepted') {
29 follow.set('state', 'accepted')
30 await follow.save()
31 await addFetchOutboxJob(targetActor)
32 }
33}