]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/users/my-blocklist.ts
hls-plugin: destroy hls upon third err
[github/Chocobozzz/PeerTube.git] / server / controllers / api / users / my-blocklist.ts
index 713c16022322a25fed2a8ab09037fd1fd4cd02a4..6eba22d52ca0e3973c66668362edfb70577774aa 100644 (file)
@@ -20,6 +20,8 @@ import {
 import { AccountBlocklistModel } from '../../../models/account/account-blocklist'
 import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist'
 import { ServerBlocklistModel } from '../../../models/server/server-blocklist'
+import { UserNotificationModel } from '@server/models/account/user-notification'
+import { logger } from '@server/helpers/logger'
 
 const myBlocklistRouter = express.Router()
 
@@ -74,7 +76,13 @@ export {
 async function listBlockedAccounts (req: express.Request, res: express.Response) {
   const user = res.locals.oauth.token.User
 
-  const resultList = await AccountBlocklistModel.listForApi(user.Account.id, req.query.start, req.query.count, req.query.sort)
+  const resultList = await AccountBlocklistModel.listForApi({
+    start: req.query.start,
+    count: req.query.count,
+    sort: req.query.sort,
+    search: req.query.search,
+    accountId: user.Account.id
+  })
 
   return res.json(getFormattedObjects(resultList.data, resultList.total))
 }
@@ -85,6 +93,12 @@ async function blockAccount (req: express.Request, res: express.Response) {
 
   await addAccountInBlocklist(user.Account.id, accountToBlock.id)
 
+  UserNotificationModel.removeNotificationsOf({
+    id: accountToBlock.id,
+    type: 'account',
+    forUserId: user.id
+  }).catch(err => logger.error('Cannot remove notifications after an account mute.', { err }))
+
   return res.status(204).end()
 }
 
@@ -99,7 +113,13 @@ async function unblockAccount (req: express.Request, res: express.Response) {
 async function listBlockedServers (req: express.Request, res: express.Response) {
   const user = res.locals.oauth.token.User
 
-  const resultList = await ServerBlocklistModel.listForApi(user.Account.id, req.query.start, req.query.count, req.query.sort)
+  const resultList = await ServerBlocklistModel.listForApi({
+    start: req.query.start,
+    count: req.query.count,
+    sort: req.query.sort,
+    search: req.query.search,
+    accountId: user.Account.id
+  })
 
   return res.json(getFormattedObjects(resultList.data, resultList.total))
 }
@@ -110,6 +130,12 @@ async function blockServer (req: express.Request, res: express.Response) {
 
   await addServerInBlocklist(user.Account.id, serverToBlock.id)
 
+  UserNotificationModel.removeNotificationsOf({
+    id: serverToBlock.id,
+    type: 'server',
+    forUserId: user.id
+  }).catch(err => logger.error('Cannot remove notifications after a server mute.', { err }))
+
   return res.status(204).end()
 }