CommentsController.coffee 1.0 KB

12345678910111213141516171819202122232425
  1. ChatApiHandler = require("../Chat/ChatApiHandler")
  2. EditorRealTimeController = require("../Editor/EditorRealTimeController")
  3. logger = require("logger-sharelatex")
  4. AuthenticationController = require('../Authentication/AuthenticationController')
  5. module.exports = CommentsController =
  6. sendComment: (req, res, next) ->
  7. {project_id, thread_id} = req.params
  8. content = req.body.content
  9. user_id = AuthenticationController.getLoggedInUserId(req)
  10. if !user_id?
  11. err = new Error('no logged-in user')
  12. return next(err)
  13. logger.log {project_id, thread_id, user_id, content}, "sending comment"
  14. ChatApiHandler.sendComment project_id, thread_id, user_id, content, (err, comment) ->
  15. return next(err) if err?
  16. EditorRealTimeController.emitToRoom project_id, "new-comment", thread_id, comment, (err)->
  17. res.send 204
  18. getThreads: (req, res, next) ->
  19. {project_id} = req.params
  20. logger.log {project_id}, "getting comment threads for project"
  21. ChatApiHandler.getThreads project_id, (err, threads) ->
  22. return next(err) if err?
  23. res.json threads