]>
Commit | Line | Data |
---|---|---|
eae0365b C |
1 | import { Transaction } from 'sequelize' |
2 | import { getServerActor } from '@server/models/application/application' | |
3 | import { logger } from '../../helpers/logger' | |
8424c402 C |
4 | import { CONFIG } from '../../initializers/config' |
5 | import { SERVER_ACTOR_NAME } from '../../initializers/constants' | |
2ba613a5 | 6 | import { ServerModel } from '../../models/server/server' |
eae0365b C |
7 | import { MActorFollowActors } from '../../types/models' |
8 | import { JobQueue } from '../job-queue' | |
8424c402 | 9 | |
eae0365b | 10 | async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors, transaction?: Transaction) { |
8424c402 C |
11 | if (!CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_BACK.ENABLED) return |
12 | ||
13 | const follower = actorFollow.ActorFollower | |
14 | ||
15 | if (follower.type === 'Application' && follower.preferredUsername === SERVER_ACTOR_NAME) { | |
16 | logger.info('Auto follow back %s.', follower.url) | |
17 | ||
18 | const me = await getServerActor() | |
19 | ||
eae0365b | 20 | const server = await ServerModel.load(follower.serverId, transaction) |
8424c402 C |
21 | const host = server.host |
22 | ||
23 | const payload = { | |
24 | host, | |
25 | name: SERVER_ACTOR_NAME, | |
26 | followerActorId: me.id, | |
27 | isAutoFollow: true | |
28 | } | |
29 | ||
bd911b54 | 30 | JobQueue.Instance.createJobAsync({ type: 'activitypub-follow', payload }) |
8424c402 C |
31 | } |
32 | } | |
33 | ||
4d029ef8 C |
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 | |
38 | ||
39 | const splitted = handleOrHost.split('@') | |
40 | if (splitted.length === 2) { | |
41 | name = splitted[0] | |
42 | host = splitted[1] | |
43 | } | |
44 | ||
45 | return { name, host } | |
46 | } | |
47 | ||
8424c402 | 48 | export { |
4d029ef8 C |
49 | autoFollowBackIfNeeded, |
50 | getRemoteNameAndHost | |
8424c402 | 51 | } |