2016-12-16 11:42:41 -05:00
|
|
|
ChatApiHandler = require("./ChatApiHandler")
|
2014-07-04 08:20:30 -04:00
|
|
|
EditorRealTimeController = require("../Editor/EditorRealTimeController")
|
2014-07-04 08:29:59 -04:00
|
|
|
logger = require("logger-sharelatex")
|
2016-09-05 10:58:31 -04:00
|
|
|
AuthenticationController = require('../Authentication/AuthenticationController')
|
2014-07-04 08:05:55 -04:00
|
|
|
|
|
|
|
module.exports =
|
2016-09-05 10:58:31 -04:00
|
|
|
sendMessage: (req, res, next)->
|
2016-12-16 11:42:41 -05:00
|
|
|
project_id = req.params.project_id
|
|
|
|
content = req.body.content
|
2016-09-05 10:58:31 -04:00
|
|
|
user_id = AuthenticationController.getLoggedInUserId(req)
|
|
|
|
if !user_id?
|
|
|
|
err = new Error('no logged-in user')
|
|
|
|
return next(err)
|
2016-12-16 11:42:41 -05:00
|
|
|
ChatApiHandler.sendGlobalMessage project_id, user_id, content, (err, message) ->
|
|
|
|
return next(err) if err?
|
|
|
|
EditorRealTimeController.emitToRoom project_id, "new-chat-message", message, (err)->
|
|
|
|
res.send(204)
|
2014-07-04 08:05:55 -04:00
|
|
|
|
2016-12-16 11:42:41 -05:00
|
|
|
getMessages: (req, res, next)->
|
|
|
|
project_id = req.params.project_id
|
2014-07-15 13:25:12 -04:00
|
|
|
query = req.query
|
2014-07-08 05:08:38 -04:00
|
|
|
logger.log project_id:project_id, query:query, "getting messages"
|
2016-12-16 11:42:41 -05:00
|
|
|
ChatApiHandler.getGlobalMessages project_id, query.limit, query.before, (err, messages) ->
|
|
|
|
return next(err) if err?
|
|
|
|
logger.log length: messages?.length, "sending messages to client"
|
|
|
|
res.json messages
|