overleaf/services/web/app/coffee/Features/Chat/ChatHandler.coffee

32 lines
782 B
CoffeeScript
Raw Normal View History

2014-07-02 12:28:05 -04:00
request = require("request")
settings = require("settings-sharelatex")
logger = require("logger-sharelatex")
module.exports =
sendMessage: (project_id, user_id, messageContent, callback)->
opts =
method:"post"
json:
content:messageContent
user_id:user_id
uri:"#{settings.apis.chat.url}/room/#{project_id}/messages"
request opts, (err, response, body)->
if err?
logger.err err:err, "problem sending new message to chat"
callback(err, body)
getMessages: (project_id, query, callback)->
qs = {}
qs.limit = query.limit if query?.limit?
qs.before = query.before if query?.before?
2014-07-02 12:28:05 -04:00
opts =
uri:"#{settings.apis.chat.url}/room/#{project_id}/messages"
method:"get"
qs: qs
2014-07-02 12:28:05 -04:00
request opts, (err, response, body)->
callback(err, body)