]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/users/my-notifications.ts
Add totalLocalVideoFilesSize in stats
[github/Chocobozzz/PeerTube.git] / server / controllers / api / users / my-notifications.ts
index 4b81777a47d27e019622a7ddd137567179c6c1eb..76cf9758794a28b4834f209877c79a8f47d5dec3 100644 (file)
@@ -18,7 +18,7 @@ import {
   markAsReadUserNotificationsValidator,
   updateNotificationSettingsValidator
 } from '../../../middlewares/validators/user-notifications'
-import { UserNotificationSetting, UserNotificationSettingValue } from '../../../../shared/models/users'
+import { UserNotificationSetting } from '../../../../shared/models/users'
 import { UserNotificationSettingModel } from '../../../models/account/user-notification-setting'
 
 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
 }
@@ -53,7 +58,7 @@ export {
 
 async function updateNotificationSettings (req: express.Request, res: express.Response) {
   const user: UserModel = res.locals.oauth.token.User
-  const body: UserNotificationSetting = req.body
+  const body = req.body
 
   const query = {
     where: {
@@ -61,14 +66,19 @@ async function updateNotificationSettings (req: express.Request, res: express.Re
     }
   }
 
-  await UserNotificationSettingModel.update({
+  const values: UserNotificationSetting = {
     newVideoFromSubscription: body.newVideoFromSubscription,
     newCommentOnMyVideo: body.newCommentOnMyVideo,
     videoAbuseAsModerator: body.videoAbuseAsModerator,
     blacklistOnMyVideo: body.blacklistOnMyVideo,
     myVideoPublished: body.myVideoPublished,
-    myVideoImportFinished: body.myVideoImportFinished
-  }, query)
+    myVideoImportFinished: body.myVideoImportFinished,
+    newFollow: body.newFollow,
+    newUserRegistration: body.newUserRegistration,
+    commentMention: body.commentMention
+  }
+
+  await UserNotificationSettingModel.update(values, query)
 
   return res.status(204).end()
 }
@@ -88,3 +98,11 @@ async function markAsReadUserNotifications (req: express.Request, res: express.R
 
   return res.status(204).end()
 }
+
+async function markAsReadAllUserNotifications (req: express.Request, res: express.Response) {
+  const user: UserModel = res.locals.oauth.token.User
+
+  await UserNotificationModel.markAllAsRead(user.id)
+
+  return res.status(204).end()
+}