2
1

send-follow.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { ActivityFollow } from '../../../../shared/models/activitypub'
  2. import { ActorModel } from '../../../models/activitypub/actor'
  3. import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
  4. import { getActorFollowActivityPubUrl } from '../url'
  5. import { unicastTo } from './utils'
  6. import { logger } from '../../../helpers/logger'
  7. function sendFollow (actorFollow: ActorFollowModel) {
  8. const me = actorFollow.ActorFollower
  9. const following = actorFollow.ActorFollowing
  10. // Same server as ours
  11. if (!following.serverId) return
  12. logger.info('Creating job to send follow request to %s.', following.url)
  13. const url = getActorFollowActivityPubUrl(me, following)
  14. const data = buildFollowActivity(url, me, following)
  15. return unicastTo(data, me, following.inboxUrl)
  16. }
  17. function buildFollowActivity (url: string, byActor: ActorModel, targetActor: ActorModel): ActivityFollow {
  18. return {
  19. type: 'Follow',
  20. id: url,
  21. actor: byActor.url,
  22. object: targetActor.url
  23. }
  24. }
  25. // ---------------------------------------------------------------------------
  26. export {
  27. sendFollow,
  28. buildFollowActivity
  29. }