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

33 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-12-12 11:53:50 -05:00
import { ActivityAccept } from '../../../../shared/models/activitypub'
2017-12-14 11:38:41 -05:00
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
2018-05-25 05:17:41 -04:00
import { addFetchOutboxJob } from '../actor'
2019-08-02 04:53:36 -04:00
import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
2019-08-15 05:53:26 -04:00
import { MActorDefault, MActorSignature } from '../../../typings/models'
2017-11-13 11:39:41 -05:00
2019-08-02 04:53:36 -04:00
async function processAcceptActivity (options: APProcessorOptions<ActivityAccept>) {
const { byActor: targetActor, inboxActor } = options
2017-12-14 11:38:41 -05:00
if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.')
2017-11-13 11:39:41 -05:00
2017-12-14 11:38:41 -05:00
return processAccept(inboxActor, targetActor)
2017-11-13 11:39:41 -05:00
}
// ---------------------------------------------------------------------------
export {
processAcceptActivity
}
// ---------------------------------------------------------------------------
2019-08-15 05:53:26 -04:00
async function processAccept (actor: MActorDefault, targetActor: MActorSignature) {
2017-12-14 11:38:41 -05:00
const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id)
2017-11-13 11:39:41 -05:00
if (!follow) throw new Error('Cannot find associated follow.')
2018-01-11 05:40:18 -05:00
if (follow.state !== 'accepted') {
follow.state = 'accepted'
2018-01-11 05:40:18 -05:00
await follow.save()
await addFetchOutboxJob(targetActor)
2018-01-11 05:40:18 -05:00
}
2017-11-13 11:39:41 -05:00
}