]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/send/send-follow.ts
Add subscriptions endpoints to REST API
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-follow.ts
index 48d641c22d1f085e9b7a8fb4810054dda1db5890..46d08c17be1e3875e7a7370bfba41de0793fbe50 100644 (file)
@@ -1,29 +1,32 @@
-import { Transaction } from 'sequelize'
-import { ActivityFollow } from '../../../../shared/models/activitypub/activity'
-import { AccountInstance } from '../../../models'
-import { AccountFollowInstance } from '../../../models/account/account-follow-interface'
-import { unicastTo } from './misc'
-import { getAccountFollowActivityPubUrl } from '../../../helpers/activitypub'
+import { ActivityFollow } from '../../../../shared/models/activitypub'
+import { ActorModel } from '../../../models/activitypub/actor'
+import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
+import { getActorFollowActivityPubUrl } from '../url'
+import { unicastTo } from './utils'
+import { logger } from '../../../helpers/logger'
 
-async function sendFollow (accountFollow: AccountFollowInstance, t: Transaction) {
-  const me = accountFollow.AccountFollower
-  const following = accountFollow.AccountFollowing
+function sendFollow (actorFollow: ActorFollowModel) {
+  const me = actorFollow.ActorFollower
+  const following = actorFollow.ActorFollowing
 
-  const url = getAccountFollowActivityPubUrl(accountFollow)
-  const data = await followActivityData(url, me, following)
+  // Same server as ours
+  if (!following.serverId) return
 
-  return unicastTo(data, me, following.inboxUrl, t)
+  logger.info('Creating job to send follow request to %s.', following.url)
+
+  const url = getActorFollowActivityPubUrl(actorFollow)
+  const data = followActivityData(url, me, following)
+
+  return unicastTo(data, me, following.inboxUrl)
 }
 
-async function followActivityData (url: string, byAccount: AccountInstance, targetAccount: AccountInstance) {
-  const activity: ActivityFollow = {
+function followActivityData (url: string, byActor: ActorModel, targetActor: ActorModel): ActivityFollow {
+  return {
     type: 'Follow',
     id: url,
-    actor: byAccount.url,
-    object: targetAccount.url
+    actor: byActor.url,
+    object: targetActor.url
   }
-
-  return activity
 }
 
 // ---------------------------------------------------------------------------