NotificationsBuilder.coffee 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. logger = require("logger-sharelatex")
  2. NotificationsHandler = require("./NotificationsHandler")
  3. module.exports =
  4. # Note: notification keys should be url-safe
  5. groupPlan: (user, licence)->
  6. key : "join-sub-#{licence.subscription_id}"
  7. create: (callback = ->)->
  8. messageOpts =
  9. groupName: licence.name
  10. subscription_id: licence.subscription_id
  11. logger.log user_id:user._id, key:@key, "creating notification key for user"
  12. NotificationsHandler.createNotification user._id, @key, "notification_group_invite", messageOpts, null, callback
  13. read: (callback = ->)->
  14. NotificationsHandler.markAsReadWithKey user._id, @key, callback
  15. projectInvite: (invite, project, sendingUser, user) ->
  16. key: "project-invite-#{invite._id}"
  17. create: (callback=()->) ->
  18. messageOpts =
  19. userName: sendingUser.first_name
  20. projectName: project.name
  21. projectId: project._id.toString()
  22. token: invite.token
  23. logger.log {user_id: user._id, project_id: project._id, invite_id: invite._id, key: @key}, "creating project invite notification for user"
  24. NotificationsHandler.createNotification user._id, @key, "notification_project_invite", messageOpts, invite.expires, callback
  25. read: (callback=()->) ->
  26. NotificationsHandler.markAsReadByKeyOnly @key, callback