2016-01-21 15:42:50 -05:00
|
|
|
NotificationsHandler = require("./NotificationsHandler")
|
2018-09-02 08:47:16 -04:00
|
|
|
NotificationsBuilder = require("./NotificationsBuilder")
|
2016-09-05 10:58:31 -04:00
|
|
|
AuthenticationController = require("../Authentication/AuthenticationController")
|
2018-09-02 08:47:16 -04:00
|
|
|
Settings = require 'settings-sharelatex'
|
2016-01-21 15:42:50 -05:00
|
|
|
logger = require("logger-sharelatex")
|
2016-01-22 15:08:39 -05:00
|
|
|
_ = require("underscore")
|
2016-01-21 15:42:50 -05:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
getAllUnreadNotifications: (req, res)->
|
2018-09-02 08:47:16 -04:00
|
|
|
ip = req.headers['x-forwarded-for'] ||
|
|
|
|
req.connection.remoteAddress ||
|
|
|
|
req.socket.remoteAddress
|
2016-09-05 10:58:31 -04:00
|
|
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
2018-09-02 08:47:16 -04:00
|
|
|
|
|
|
|
# in v2 add notifications for matching university IPs
|
|
|
|
if Settings.overleaf?
|
|
|
|
NotificationsBuilder.ipMatcherAffiliation(user_id, ip)
|
|
|
|
|
2016-09-05 10:58:31 -04:00
|
|
|
NotificationsHandler.getUserNotifications user_id, (err, unreadNotifications)->
|
|
|
|
unreadNotifications = _.map unreadNotifications, (notification)->
|
2016-01-22 15:08:39 -05:00
|
|
|
notification.html = req.i18n.translate(notification.templateKey, notification.messageOpts)
|
|
|
|
return notification
|
2016-01-21 15:42:50 -05:00
|
|
|
res.send(unreadNotifications)
|
|
|
|
|
|
|
|
markNotificationAsRead: (req, res)->
|
2016-09-05 10:58:31 -04:00
|
|
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
2016-01-21 15:42:50 -05:00
|
|
|
notification_id = req.params.notification_id
|
|
|
|
NotificationsHandler.markAsRead user_id, notification_id, ->
|
|
|
|
res.send()
|
|
|
|
logger.log user_id:user_id, notification_id:notification_id, "mark notification as read"
|