]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/follow.ts
Merge branch 'release/5.0.0' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / follow.ts
CommitLineData
eae0365b
C
1import { Transaction } from 'sequelize'
2import { getServerActor } from '@server/models/application/application'
3import { logger } from '../../helpers/logger'
8424c402
C
4import { CONFIG } from '../../initializers/config'
5import { SERVER_ACTOR_NAME } from '../../initializers/constants'
2ba613a5 6import { ServerModel } from '../../models/server/server'
eae0365b
C
7import { MActorFollowActors } from '../../types/models'
8import { JobQueue } from '../job-queue'
8424c402 9
eae0365b 10async 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
35function 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 48export {
4d029ef8
C
49 autoFollowBackIfNeeded,
50 getRemoteNameAndHost
8424c402 51}