X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fusers%2Fmy-notifications.ts;h=017f5219edeb5a3b65bf6bbe855243d7d35aaefb;hb=338eb9d33af690db716805fd2277bf68f473b58f;hp=d74d26add62c4ea17817313334b0f835cbbfc90f;hpb=f7cc67b455a12ccae9b0ea16876d166720364357;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/users/my-notifications.ts b/server/controllers/api/users/my-notifications.ts index d74d26add..017f5219e 100644 --- a/server/controllers/api/users/my-notifications.ts +++ b/server/controllers/api/users/my-notifications.ts @@ -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' @@ -45,6 +44,11 @@ myNotificationsRouter.post('/me/notifications/read', asyncMiddleware(markAsReadUserNotifications) ) +myNotificationsRouter.post('/me/notifications/read-all', + authenticate, + asyncMiddleware(markAsReadAllUserNotifications) +) + export { myNotificationsRouter } @@ -52,8 +56,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: { @@ -65,12 +69,15 @@ async function updateNotificationSettings (req: express.Request, res: express.Re newVideoFromSubscription: body.newVideoFromSubscription, newCommentOnMyVideo: body.newCommentOnMyVideo, videoAbuseAsModerator: body.videoAbuseAsModerator, + 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 } await UserNotificationSettingModel.update(values, query) @@ -79,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 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 +94,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() } + +async function markAsReadAllUserNotifications (req: express.Request, res: express.Response) { + const user = res.locals.oauth.token.User + + await UserNotificationModel.markAllAsRead(user.id) + + return res.status(204).end() +}