2016-06-15 16:38:02 +00:00
|
|
|
logger = require("logger-sharelatex")
|
2016-02-05 14:13:38 +00:00
|
|
|
NotificationsHandler = require("./NotificationsHandler")
|
|
|
|
|
2016-08-05 15:11:03 +00:00
|
|
|
module.exports =
|
2016-02-05 14:13:38 +00:00
|
|
|
|
2016-08-11 13:04:11 +00:00
|
|
|
# Note: notification keys should be url-safe
|
|
|
|
|
2016-02-05 14:13:38 +00:00
|
|
|
groupPlan: (user, licence)->
|
|
|
|
key : "join-sub-#{licence.subscription_id}"
|
|
|
|
create: (callback = ->)->
|
2016-08-05 15:11:03 +00:00
|
|
|
messageOpts =
|
2016-02-05 14:13:38 +00:00
|
|
|
groupName: licence.name
|
|
|
|
subscription_id: licence.subscription_id
|
2016-08-31 08:40:40 +00:00
|
|
|
logger.log user_id:user._id, key:@key, "creating notification key for user"
|
2016-08-30 12:07:37 +00:00
|
|
|
NotificationsHandler.createNotification user._id, @key, "notification_group_invite", messageOpts, null, callback
|
2016-02-05 14:13:38 +00:00
|
|
|
|
|
|
|
read: (callback = ->)->
|
2016-02-17 16:24:09 +00:00
|
|
|
NotificationsHandler.markAsReadWithKey user._id, @key, callback
|
2016-08-05 15:11:03 +00:00
|
|
|
|
|
|
|
projectInvite: (invite, project, sendingUser, user) ->
|
|
|
|
key: "project-invite-#{invite._id}"
|
|
|
|
create: (callback=()->) ->
|
|
|
|
messageOpts =
|
|
|
|
userName: sendingUser.first_name
|
|
|
|
projectName: project.name
|
|
|
|
projectId: project._id.toString()
|
|
|
|
token: invite.token
|
|
|
|
logger.log {user_id: user._id, project_id: project._id, invite_id: invite._id, key: @key}, "creating project invite notification for user"
|
2016-08-30 12:07:37 +00:00
|
|
|
NotificationsHandler.createNotification user._id, @key, "notification_project_invite", messageOpts, invite.expires, callback
|
2016-08-05 15:11:03 +00:00
|
|
|
read: (callback=()->) ->
|
2016-08-11 13:04:11 +00:00
|
|
|
NotificationsHandler.markAsReadByKeyOnly @key, callback
|