chat.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Chat plugin for collaboration, need to list available users.
  2. , and notify when the message comes in by flashing chat "Open" link*/
  3. const {
  4. __errorContinuable,
  5. __httpReq,
  6. __wHttpReq,
  7. __postInternalErrorMsg, __postMessage,
  8. __sequenceNumber,
  9. __successContinuable,
  10. __uri_to_id
  11. } = require("../__worker");
  12. module.exports = {
  13. 'interfaces' : [{'method':'POST', 'url=':'/chat'}],
  14. 'localcontext' : {'messages':[]},
  15. 'csworker' :
  16. function(resp,method,uri,reqData,wcontext)
  17. {
  18. var self = this;
  19. _do.chain(
  20. [__wHttpReq(method, uri+'?wid='+wcontext.__aswid, reqData)])(
  21. function()
  22. {
  23. self.localcontext.messages.push(reqData);
  24. __postMessage(
  25. {'statusCode':200,
  26. 'changelog':
  27. [{'op':'CHAT',
  28. 'text':self.localcontext.messages.pop()}],
  29. 'sequence#':__sequenceNumber(),
  30. 'respIndex':resp});
  31. },
  32. function(err) {__postInternalErrorMsg(resp,err);}
  33. );
  34. },
  35. 'asworker' :
  36. function(resp,method,uri,reqData,wcontext)
  37. {
  38. __postMessage(
  39. {'statusCode':200,
  40. 'changelog':
  41. [],
  42. 'sequence#':__sequenceNumber(),
  43. 'respIndex':resp});
  44. }
  45. };