1
0
Fork 0
peertube/server/lib/activitypub/process/process-accept.ts

30 lines
1.1 KiB
TypeScript
Raw Normal View History

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