1 import { Transaction } from 'sequelize'
2 import { getServerActor } from '@server/models/application/application'
3 import { logger } from '../../helpers/logger'
4 import { CONFIG } from '../../initializers/config'
5 import { SERVER_ACTOR_NAME } from '../../initializers/constants'
6 import { ServerModel } from '../../models/server/server'
7 import { MActorFollowActors } from '../../types/models'
8 import { JobQueue } from '../job-queue'
10 async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors, transaction?: Transaction) {
11 if (!CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_BACK.ENABLED) return
13 const follower = actorFollow.ActorFollower
15 if (follower.type === 'Application' && follower.preferredUsername === SERVER_ACTOR_NAME) {
16 logger.info('Auto follow back %s.', follower.url)
18 const me = await getServerActor()
20 const server = await ServerModel.load(follower.serverId, transaction)
21 const host = server.host
25 name: SERVER_ACTOR_NAME,
26 followerActorId: me.id,
30 JobQueue.Instance.createJob({ type: 'activitypub-follow', payload })
34 // If we only have an host, use a default account handle
35 function getRemoteNameAndHost (handleOrHost: string) {
36 let name = SERVER_ACTOR_NAME
37 let host = handleOrHost
39 const splitted = handleOrHost.split('@')
40 if (splitted.length === 2) {
49 autoFollowBackIfNeeded,