aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/follow.ts
blob: 3b5ad47c93ba8491ab76789afb7452461450560f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { MActorFollowActors } from '../../typings/models'
import { CONFIG } from '../../initializers/config'
import { SERVER_ACTOR_NAME } from '../../initializers/constants'
import { JobQueue } from '../job-queue'
import { logger } from '../../helpers/logger'
import { ServerModel } from '../../models/server/server'
import { getServerActor } from '@server/models/application/application'

async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors) {
  if (!CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_BACK.ENABLED) return

  const follower = actorFollow.ActorFollower

  if (follower.type === 'Application' && follower.preferredUsername === SERVER_ACTOR_NAME) {
    logger.info('Auto follow back %s.', follower.url)

    const me = await getServerActor()

    const server = await ServerModel.load(follower.serverId)
    const host = server.host

    const payload = {
      host,
      name: SERVER_ACTOR_NAME,
      followerActorId: me.id,
      isAutoFollow: true
    }

    JobQueue.Instance.createJob({ type: 'activitypub-follow', payload })
  }
}

export {
  autoFollowBackIfNeeded
}