2021-06-15 09:17:19 +02:00
|
|
|
import { Transaction } from 'sequelize'
|
|
|
|
import { getServerActor } from '@server/models/application/application'
|
|
|
|
import { logger } from '../../helpers/logger'
|
2019-08-30 16:50:12 +02:00
|
|
|
import { CONFIG } from '../../initializers/config'
|
|
|
|
import { SERVER_ACTOR_NAME } from '../../initializers/constants'
|
2019-09-04 15:50:40 +02:00
|
|
|
import { ServerModel } from '../../models/server/server'
|
2021-06-15 09:17:19 +02:00
|
|
|
import { MActorFollowActors } from '../../types/models'
|
|
|
|
import { JobQueue } from '../job-queue'
|
2019-08-30 16:50:12 +02:00
|
|
|
|
2021-06-15 09:17:19 +02:00
|
|
|
async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors, transaction?: Transaction) {
|
2019-08-30 16:50:12 +02:00
|
|
|
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()
|
|
|
|
|
2021-06-15 09:17:19 +02:00
|
|
|
const server = await ServerModel.load(follower.serverId, transaction)
|
2019-08-30 16:50:12 +02:00
|
|
|
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
|
|
|
|
}
|