2
1

send-reject.ts 1.4 KB

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