]> 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 cef1d237c0f3725c859ef3ea69c6a8ac15e40e7f..76cf9758794a28b4834f209877c79a8f47d5dec3 100644 (file)
@@ -14,6 +14,7 @@ import { getFormattedObjects } from '../../../helpers/utils'
 import { UserNotificationModel } from '../../../models/account/user-notification'
 import { meRouter } from './me'
 import {
+  listUserNotificationsValidator,
   markAsReadUserNotificationsValidator,
   updateNotificationSettingsValidator
 } from '../../../middlewares/validators/user-notifications'
@@ -34,6 +35,7 @@ myNotificationsRouter.get('/me/notifications',
   userNotificationsSortValidator,
   setDefaultSort,
   setDefaultPagination,
+  listUserNotificationsValidator,
   asyncMiddleware(listUserNotifications)
 )
 
@@ -43,6 +45,11 @@ myNotificationsRouter.post('/me/notifications/read',
   asyncMiddleware(markAsReadUserNotifications)
 )
 
+myNotificationsRouter.post('/me/notifications/read-all',
+  authenticate,
+  asyncMiddleware(markAsReadAllUserNotifications)
+)
+
 export {
   myNotificationsRouter
 }
@@ -51,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: {
@@ -59,10 +66,19 @@ async function updateNotificationSettings (req: express.Request, res: express.Re
     }
   }
 
-  await UserNotificationSettingModel.update({
+  const values: UserNotificationSetting = {
     newVideoFromSubscription: body.newVideoFromSubscription,
-    newCommentOnMyVideo: body.newCommentOnMyVideo
-  }, query)
+    newCommentOnMyVideo: body.newCommentOnMyVideo,
+    videoAbuseAsModerator: body.videoAbuseAsModerator,
+    blacklistOnMyVideo: body.blacklistOnMyVideo,
+    myVideoPublished: body.myVideoPublished,
+    myVideoImportFinished: body.myVideoImportFinished,
+    newFollow: body.newFollow,
+    newUserRegistration: body.newUserRegistration,
+    commentMention: body.commentMention
+  }
+
+  await UserNotificationSettingModel.update(values, query)
 
   return res.status(204).end()
 }
@@ -70,7 +86,7 @@ async function updateNotificationSettings (req: express.Request, res: express.Re
 async function listUserNotifications (req: express.Request, res: express.Response) {
   const user: UserModel = res.locals.oauth.token.User
 
-  const resultList = await UserNotificationModel.listForApi(user.id, req.query.start, req.query.count, req.query.sort)
+  const resultList = await UserNotificationModel.listForApi(user.id, req.query.start, req.query.count, req.query.sort, req.query.unread)
 
   return res.json(getFormattedObjects(resultList.data, resultList.total))
 }
@@ -82,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()
+}