]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/follow.ts
Merge branch 'feature/improve-live' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / follow.ts
index a1c95504e3d7d6af694598bc5b8c8b306592d99a..f6e2a48fdec3e889bb04a9c72d832fbb110eef35 100644 (file)
@@ -1,12 +1,13 @@
-import { MActorFollowActors } from '../../typings/models'
+import { Transaction } from 'sequelize'
+import { getServerActor } from '@server/models/application/application'
+import { logger } from '../../helpers/logger'
 import { CONFIG } from '../../initializers/config'
 import { SERVER_ACTOR_NAME } from '../../initializers/constants'
-import { JobQueue } from '../job-queue'
-import { logger } from '../../helpers/logger'
-import { getServerActor } from '../../helpers/utils'
 import { ServerModel } from '../../models/server/server'
+import { MActorFollowActors } from '../../types/models'
+import { JobQueue } from '../job-queue'
 
-async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors) {
+async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors, transaction?: Transaction) {
   if (!CONFIG.FOLLOWINGS.INSTANCE.AUTO_FOLLOW_BACK.ENABLED) return
 
   const follower = actorFollow.ActorFollower
@@ -16,7 +17,7 @@ async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors) {
 
     const me = await getServerActor()
 
-    const server = await ServerModel.load(follower.serverId)
+    const server = await ServerModel.load(follower.serverId, transaction)
     const host = server.host
 
     const payload = {
@@ -26,10 +27,25 @@ async function autoFollowBackIfNeeded (actorFollow: MActorFollowActors) {
       isAutoFollow: true
     }
 
-    JobQueue.Instance.createJob({ type: 'activitypub-follow', payload })
+    JobQueue.Instance.createJobAsync({ type: 'activitypub-follow', payload })
   }
 }
 
+// If we only have an host, use a default account handle
+function getRemoteNameAndHost (handleOrHost: string) {
+  let name = SERVER_ACTOR_NAME
+  let host = handleOrHost
+
+  const splitted = handleOrHost.split('@')
+  if (splitted.length === 2) {
+    name = splitted[0]
+    host = splitted[1]
+  }
+
+  return { name, host }
+}
+
 export {
-  autoFollowBackIfNeeded
+  autoFollowBackIfNeeded,
+  getRemoteNameAndHost
 }