]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-follow.ts
Fix HLS federation
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-follow.ts
index 24c9085f7ac77520a537e713e8c09a336518341c..0cd537187a93ccacc939d85f0258ef473f68a28b 100644 (file)
@@ -5,9 +5,11 @@ import { sequelizeTypescript } from '../../../initializers'
 import { ActorModel } from '../../../models/activitypub/actor'
 import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
 import { sendAccept } from '../send'
+import { Notifier } from '../../notifier'
+import { getAPId } from '../../../helpers/activitypub'
 
 async function processFollowActivity (activity: ActivityFollow, byActor: ActorModel) {
-  const activityObject = activity.object
+  const activityObject = getAPId(activity.object)
 
   return retryTransactionWrapper(processFollow, byActor, activityObject)
 }
@@ -21,13 +23,13 @@ export {
 // ---------------------------------------------------------------------------
 
 async function processFollow (actor: ActorModel, targetActorURL: string) {
-  await sequelizeTypescript.transaction(async t => {
+  const { actorFollow, created } = await sequelizeTypescript.transaction(async t => {
     const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t)
 
     if (!targetActor) throw new Error('Unknown actor')
     if (targetActor.isOwned() === false) throw new Error('This is not a local actor.')
 
-    const [ actorFollow ] = await ActorFollowModel.findOrCreate({
+    const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({
       where: {
         actorId: actor.id,
         targetActorId: targetActor.id
@@ -52,8 +54,12 @@ async function processFollow (actor: ActorModel, targetActorURL: string) {
     actorFollow.ActorFollowing = targetActor
 
     // Target sends to actor he accepted the follow request
-    return sendAccept(actorFollow)
+    await sendAccept(actorFollow)
+
+    return { actorFollow, created }
   })
 
+  if (created) Notifier.Instance.notifyOfNewFollow(actorFollow)
+
   logger.info('Actor %s is followed by actor %s.', targetActorURL, actor.url)
 }