send-accept.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { ActivityAccept, ActivityFollow } from '../../../../shared/models/activitypub'
  2. import { ActorModel } from '../../../models/activitypub/actor'
  3. import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
  4. import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url'
  5. import { unicastTo } from './utils'
  6. import { buildFollowActivity } from './send-follow'
  7. import { logger } from '../../../helpers/logger'
  8. async function sendAccept (actorFollow: ActorFollowModel) {
  9. const follower = actorFollow.ActorFollower
  10. const me = actorFollow.ActorFollowing
  11. if (!follower.serverId) { // This should never happen
  12. logger.warn('Do not sending accept to local follower.')
  13. return
  14. }
  15. logger.info('Creating job to accept follower %s.', follower.url)
  16. const followUrl = getActorFollowActivityPubUrl(actorFollow)
  17. const followData = buildFollowActivity(followUrl, follower, me)
  18. const url = getActorFollowAcceptActivityPubUrl(actorFollow)
  19. const data = buildAcceptActivity(url, me, followData)
  20. return unicastTo(data, me, follower.inboxUrl)
  21. }
  22. // ---------------------------------------------------------------------------
  23. export {
  24. sendAccept
  25. }
  26. // ---------------------------------------------------------------------------
  27. function buildAcceptActivity (url: string, byActor: ActorModel, followActivityData: ActivityFollow): ActivityAccept {
  28. return {
  29. type: 'Accept',
  30. id: url,
  31. actor: byActor.url,
  32. object: followActivityData
  33. }
  34. }