follow.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { MActorFollowActors } from '../../types/models'
  2. import { CONFIG } from '../../initializers/config'
  3. import { SERVER_ACTOR_NAME } from '../../initializers/constants'
  4. import { JobQueue } from '../job-queue'
  5. import { logger } from '../../helpers/logger'
  6. import { ServerModel } from '../../models/server/server'
  7. import { getServerActor } from '@server/models/application/application'
  8. async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors) {
  9. if (!CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_BACK.ENABLED) return
  10. const follower = actorFollow.ActorFollower
  11. if (follower.type === 'Application' && follower.preferredUsername === SERVER_ACTOR_NAME) {
  12. logger.info('Auto follow back %s.', follower.url)
  13. const me = await getServerActor()
  14. const server = await ServerModel.load(follower.serverId)
  15. const host = server.host
  16. const payload = {
  17. host,
  18. name: SERVER_ACTOR_NAME,
  19. followerActorId: me.id,
  20. isAutoFollow: true
  21. }
  22. JobQueue.Instance.createJob({ type: 'activitypub-follow', payload })
  23. }
  24. }
  25. export {
  26. autoFollowBackIfNeeded
  27. }