]> 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 4b54afc8d9f798ae4879b548ab7a20ba9489c972..535d530f75a4cbbd7c52f6a001c2696bbb02d407 100644 (file)
@@ -1,11 +1,15 @@
 import * as express from 'express'
 import { UserRight } from '../../../../shared/models/users/user-right.enum'
 import { getFormattedObjects } from '../../../helpers'
+import { retryTransactionWrapper } from '../../../helpers/database-utils'
 import { logger } from '../../../helpers/logger'
 import { getServerAccount } from '../../../helpers/utils'
 import { getAccountFromWebfinger } from '../../../helpers/webfinger'
 import { SERVER_ACCOUNT_NAME } from '../../../initializers/constants'
 import { database as db } from '../../../initializers/database'
+import { saveAccountAndServerIfNotExist } from '../../../lib/activitypub/account'
+import { sendUndoFollow } from '../../../lib/activitypub/send/send-undo'
+import { sendFollow } from '../../../lib/index'
 import { asyncMiddleware, paginationValidator, removeFollowingValidator, setFollowersSort, setPagination } from '../../../middlewares'
 import { authenticate } from '../../../middlewares/oauth'
 import { setBodyHostsPort } from '../../../middlewares/servers'
@@ -13,13 +17,8 @@ import { setFollowingSort } from '../../../middlewares/sort'
 import { ensureUserHasRight } from '../../../middlewares/user-right'
 import { followValidator } from '../../../middlewares/validators/follows'
 import { followersSortValidator, followingSortValidator } from '../../../middlewares/validators/sort'
-import { AccountFollowInstance } from '../../../models/index'
-import { sendFollow } from '../../../lib/index'
-import { sendUndoFollow } from '../../../lib/activitypub/send/send-undo'
 import { AccountInstance } from '../../../models/account/account-interface'
-import { retryTransactionWrapper } from '../../../helpers/database-utils'
-import { saveAccountAndServerIfNotExist } from '../../../lib/activitypub/account'
-import { addFetchOutboxJob } from '../../../lib/activitypub/fetch'
+import { AccountFollowInstance } from '../../../models/index'
 
 const serverFollowsRouter = express.Router()
 
@@ -137,8 +136,6 @@ async function follow (fromAccount: AccountInstance, targetAccount: AccountInsta
       if (accountFollow.state === 'pending') {
         await sendFollow(accountFollow, t)
       }
-
-      await addFetchOutboxJob(targetAccount, t)
     })
   } catch (err) {
     // Reset target account
@@ -151,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()
 }