PeerTube/server/lib/activitypub/process/process-accept.ts

34 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-12-12 17:53:50 +01:00
import { ActivityAccept } from '../../../../shared/models/activitypub'
import { getActorUrl } from '../../../helpers/activitypub'
2017-12-14 17:38:41 +01:00
import { ActorModel } from '../../../models/activitypub/actor'
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
2018-05-25 11:17:41 +02:00
import { addFetchOutboxJob } from '../actor'
2017-11-13 17:39:41 +01:00
2017-12-14 17:38:41 +01:00
async function processAcceptActivity (activity: ActivityAccept, inboxActor?: ActorModel) {
if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.')
2017-11-13 17:39:41 +01:00
const actorUrl = getActorUrl(activity.actor)
const targetActor = await ActorModel.loadByUrl(actorUrl)
2017-11-13 17:39:41 +01:00
2017-12-14 17:38:41 +01:00
return processAccept(inboxActor, targetActor)
2017-11-13 17:39:41 +01:00
}
// ---------------------------------------------------------------------------
export {
processAcceptActivity
}
// ---------------------------------------------------------------------------
2017-12-14 17:38:41 +01:00
async function processAccept (actor: ActorModel, targetActor: ActorModel) {
const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id)
2017-11-13 17:39:41 +01:00
if (!follow) throw new Error('Cannot find associated follow.')
2018-01-11 11:40:18 +01:00
if (follow.state !== 'accepted') {
follow.set('state', 'accepted')
await follow.save()
await addFetchOutboxJob(targetActor)
2018-01-11 11:40:18 +01:00
}
2017-11-13 17:39:41 +01:00
}