2014-07-04 08:05:55 -04:00
|
|
|
ChatHandler = require("./ChatHandler")
|
2014-07-04 08:20:30 -04:00
|
|
|
EditorRealTimeController = require("../Editor/EditorRealTimeController")
|
2014-07-04 08:29:59 -04:00
|
|
|
logger = require("logger-sharelatex")
|
2014-07-04 08:05:55 -04:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
|
2014-07-08 05:08:38 -04:00
|
|
|
sendMessage: (req, res)->
|
2014-07-14 17:11:41 -04:00
|
|
|
project_id = req.params.Project_id
|
2014-07-08 05:08:38 -04:00
|
|
|
user_id = req.session.user._id
|
|
|
|
messageContent = req.body.content
|
2014-07-04 08:20:30 -04:00
|
|
|
ChatHandler.sendMessage project_id, user_id, messageContent, (err, builtMessge)->
|
2014-07-04 08:29:59 -04:00
|
|
|
if err?
|
|
|
|
logger.err err:err, project_id:project_id, user_id:user_id, messageContent:messageContent, "problem sending message to chat api"
|
2014-07-08 05:08:38 -04:00
|
|
|
return res.send(500)
|
2014-07-04 08:20:30 -04:00
|
|
|
EditorRealTimeController.emitToRoom project_id, "new-chat-message", builtMessge, (err)->
|
2014-07-08 05:08:38 -04:00
|
|
|
res.send()
|
2014-07-04 08:05:55 -04:00
|
|
|
|
2014-07-08 05:08:38 -04:00
|
|
|
getMessages: (req, res)->
|
2014-07-14 17:11:41 -04:00
|
|
|
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"
|
|
|
|
ChatHandler.getMessages project_id, query, (err, messages)->
|
2014-07-04 08:29:59 -04:00
|
|
|
if err?
|
|
|
|
logger.err err:err, query:query, "problem getting messages from chat api"
|
2014-07-08 05:08:38 -04:00
|
|
|
return res.send 500
|
2015-02-23 05:18:48 -05:00
|
|
|
logger.log length:messages?.length, "sending messages to client"
|
2015-05-19 06:04:52 -04:00
|
|
|
res.set 'Content-Type', 'application/json'
|
2014-07-08 05:08:38 -04:00
|
|
|
res.send messages
|