X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fusers%2Fmy-blocklist.ts;h=6eba22d52ca0e3973c66668362edfb70577774aa;hb=adc1f09c0dbd997f34028c1c82d1c118dc8ead80;hp=9575eab46261e05b09f745a899431a6503dad325;hpb=88108880bbdba473cfe36ecbebc1c3c4f972e102;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/users/my-blocklist.ts b/server/controllers/api/users/my-blocklist.ts index 9575eab46..6eba22d52 100644 --- a/server/controllers/api/users/my-blocklist.ts +++ b/server/controllers/api/users/my-blocklist.ts @@ -17,12 +17,11 @@ import { serversBlocklistSortValidator, unblockServerByAccountValidator } from '../../../middlewares/validators' -import { UserModel } from '../../../models/account/user' -import { AccountModel } from '../../../models/account/account' import { AccountBlocklistModel } from '../../../models/account/account-blocklist' import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../../../lib/blocklist' import { ServerBlocklistModel } from '../../../models/server/server-blocklist' -import { ServerModel } from '../../../models/server/server' +import { UserNotificationModel } from '@server/models/account/user-notification' +import { logger } from '@server/helpers/logger' const myBlocklistRouter = express.Router() @@ -75,24 +74,36 @@ export { // --------------------------------------------------------------------------- async function listBlockedAccounts (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.oauth.token.User + 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)) } async function blockAccount (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.oauth.token.User - const accountToBlock: AccountModel = res.locals.account + const user = res.locals.oauth.token.User + const accountToBlock = res.locals.account 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() } async function unblockAccount (req: express.Request, res: express.Response) { - const accountBlock: AccountBlocklistModel = res.locals.accountBlock + const accountBlock = res.locals.accountBlock await removeAccountFromBlocklist(accountBlock) @@ -100,24 +111,36 @@ async function unblockAccount (req: express.Request, res: express.Response) { } async function listBlockedServers (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.oauth.token.User + 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)) } async function blockServer (req: express.Request, res: express.Response) { - const user: UserModel = res.locals.oauth.token.User - const serverToBlock: ServerModel = res.locals.server + const user = res.locals.oauth.token.User + const serverToBlock = res.locals.server 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() } async function unblockServer (req: express.Request, res: express.Response) { - const serverBlock: ServerBlocklistModel = res.locals.serverBlock + const serverBlock = res.locals.serverBlock await removeServerFromBlocklist(serverBlock)