2
1

process-accept.ts 1.1 KB

123456789101112131415161718192021222324252627282930
  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. async function processAcceptActivity (activity: ActivityAccept, targetActor: ActorModel, inboxActor?: ActorModel) {
  6. if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.')
  7. return processAccept(inboxActor, targetActor)
  8. }
  9. // ---------------------------------------------------------------------------
  10. export {
  11. processAcceptActivity
  12. }
  13. // ---------------------------------------------------------------------------
  14. async function processAccept (actor: ActorModel, targetActor: ActorModel) {
  15. const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id)
  16. if (!follow) throw new Error('Cannot find associated follow.')
  17. if (follow.state !== 'accepted') {
  18. follow.set('state', 'accepted')
  19. await follow.save()
  20. await addFetchOutboxJob(targetActor)
  21. }
  22. }