NotificationsController.coffee 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. NotificationsHandler = require("./NotificationsHandler")
  2. NotificationsBuilder = require("./NotificationsBuilder")
  3. AuthenticationController = require("../Authentication/AuthenticationController")
  4. Settings = require 'settings-sharelatex'
  5. logger = require("logger-sharelatex")
  6. _ = require("underscore")
  7. module.exports =
  8. getAllUnreadNotifications: (req, res)->
  9. ip = req.headers['x-forwarded-for'] ||
  10. req.connection.remoteAddress ||
  11. req.socket.remoteAddress
  12. user_id = AuthenticationController.getLoggedInUserId(req)
  13. # in v2 add notifications for matching university IPs
  14. if Settings.overleaf?
  15. NotificationsBuilder.ipMatcherAffiliation(user_id, ip).create((err) ->
  16. return err
  17. )
  18. NotificationsHandler.getUserNotifications user_id, (err, unreadNotifications)->
  19. unreadNotifications = _.map unreadNotifications, (notification)->
  20. notification.html = req.i18n.translate(notification.templateKey, notification.messageOpts)
  21. return notification
  22. res.send(unreadNotifications)
  23. markNotificationAsRead: (req, res)->
  24. user_id = AuthenticationController.getLoggedInUserId(req)
  25. notification_id = req.params.notification_id
  26. NotificationsHandler.markAsRead user_id, notification_id, ->
  27. res.send()
  28. logger.log user_id:user_id, notification_id:notification_id, "mark notification as read"