]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/server/follows.ts
Update readme, architecture
[github/Chocobozzz/PeerTube.git] / server / controllers / api / server / follows.ts
index 391f8bdcad5cea5760f0c773a40a6fef52250206..535d530f75a4cbbd7c52f6a001c2696bbb02d407 100644 (file)
@@ -148,10 +148,17 @@ async function removeFollow (req: express.Request, res: express.Response, next:
   const follow: AccountFollowInstance = res.locals.follow
 
   await db.sequelize.transaction(async t => {
-    await sendUndoFollow(follow, t)
+    if (follow.state === 'accepted') await sendUndoFollow(follow, t)
+
     await follow.destroy({ transaction: t })
   })
 
+  // Destroy the account that will destroy video channels, videos and video files too
+  // This could be long so don't wait this task
+  const following = follow.AccountFollowing
+  following.destroy()
+    .catch(err => logger.error('Cannot destroy account that we do not follow anymore %s.', following.url, err))
+
   return res.status(204).end()
 }