]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/users/my-notifications.ts
Remove traefik docker support
[github/Chocobozzz/PeerTube.git] / server / controllers / api / users / my-notifications.ts
index d74d26add62c4ea17817313334b0f835cbbfc90f..5f5e4c5e6be8e1e91e075a2dfd99ba8338ddc539 100644 (file)
@@ -9,7 +9,6 @@ import {
   setDefaultSort,
   userNotificationsSortValidator
 } from '../../../middlewares'
-import { UserModel } from '../../../models/account/user'
 import { getFormattedObjects } from '../../../helpers/utils'
 import { UserNotificationModel } from '../../../models/account/user-notification'
 import { meRouter } from './me'
@@ -20,6 +19,7 @@ import {
 } from '../../../middlewares/validators/user-notifications'
 import { UserNotificationSetting } from '../../../../shared/models/users'
 import { UserNotificationSettingModel } from '../../../models/account/user-notification-setting'
+import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
 
 const myNotificationsRouter = express.Router()
 
@@ -45,6 +45,11 @@ myNotificationsRouter.post('/me/notifications/read',
   asyncMiddleware(markAsReadUserNotifications)
 )
 
+myNotificationsRouter.post('/me/notifications/read-all',
+  authenticate,
+  asyncMiddleware(markAsReadAllUserNotifications)
+)
+
 export {
   myNotificationsRouter
 }
@@ -52,8 +57,8 @@ export {
 // ---------------------------------------------------------------------------
 
 async function updateNotificationSettings (req: express.Request, res: express.Response) {
-  const user: UserModel = res.locals.oauth.token.User
-  const body = req.body
+  const user = res.locals.oauth.token.User
+  const body = req.body as UserNotificationSetting
 
   const query = {
     where: {
@@ -64,22 +69,27 @@ async function updateNotificationSettings (req: express.Request, res: express.Re
   const values: UserNotificationSetting = {
     newVideoFromSubscription: body.newVideoFromSubscription,
     newCommentOnMyVideo: body.newCommentOnMyVideo,
-    videoAbuseAsModerator: body.videoAbuseAsModerator,
+    abuseAsModerator: body.abuseAsModerator,
+    videoAutoBlacklistAsModerator: body.videoAutoBlacklistAsModerator,
     blacklistOnMyVideo: body.blacklistOnMyVideo,
     myVideoPublished: body.myVideoPublished,
     myVideoImportFinished: body.myVideoImportFinished,
     newFollow: body.newFollow,
     newUserRegistration: body.newUserRegistration,
     commentMention: body.commentMention,
+    newInstanceFollower: body.newInstanceFollower,
+    autoInstanceFollowing: body.autoInstanceFollowing,
+    abuseNewMessage: body.abuseNewMessage,
+    abuseStateChange: body.abuseStateChange
   }
 
   await UserNotificationSettingModel.update(values, query)
 
-  return res.status(204).end()
+  return res.status(HttpStatusCode.NO_CONTENT_204).end()
 }
 
 async function listUserNotifications (req: express.Request, res: express.Response) {
-  const user: UserModel = res.locals.oauth.token.User
+  const user = res.locals.oauth.token.User
 
   const resultList = await UserNotificationModel.listForApi(user.id, req.query.start, req.query.count, req.query.sort, req.query.unread)
 
@@ -87,9 +97,17 @@ async function listUserNotifications (req: express.Request, res: express.Respons
 }
 
 async function markAsReadUserNotifications (req: express.Request, res: express.Response) {
-  const user: UserModel = res.locals.oauth.token.User
+  const user = res.locals.oauth.token.User
 
   await UserNotificationModel.markAsRead(user.id, req.body.ids)
 
-  return res.status(204).end()
+  return res.status(HttpStatusCode.NO_CONTENT_204).end()
+}
+
+async function markAsReadAllUserNotifications (req: express.Request, res: express.Response) {
+  const user = res.locals.oauth.token.User
+
+  await UserNotificationModel.markAllAsRead(user.id)
+
+  return res.status(HttpStatusCode.NO_CONTENT_204).end()
 }