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

32 lines
800 B
CoffeeScript
Raw Normal View History

2014-07-02 16:28:05 +00: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
2014-07-17 10:43:12 +00:00
uri:"#{settings.apis.chat.internal_url}/room/#{project_id}/messages"
2014-07-02 16:28:05 +00:00
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 16:28:05 +00:00
opts =
2014-07-17 10:43:12 +00:00
uri:"#{settings.apis.chat.internal_url}/room/#{project_id}/messages"
2014-07-02 16:28:05 +00:00
method:"get"
qs: qs
2014-07-02 16:28:05 +00:00
request opts, (err, response, body)->
callback(err, body)