Built motion from commit 5e31ea4.|0.0.32
[motion.git] / server / api / report_chat / report_chat.socket.js
index 50de784..21c35bc 100644 (file)
@@ -1 +1,39 @@
-var _0xe1d1=["\x75\x73\x65\x20\x73\x74\x72\x69\x63\x74","\x52\x65\x70\x6F\x72\x74\x43\x68\x61\x74","\x2E\x2E\x2F\x2E\x2E\x2F\x6D\x6F\x64\x65\x6C\x73","\x72\x65\x67\x69\x73\x74\x65\x72","\x61\x66\x74\x65\x72\x43\x72\x65\x61\x74\x65","\x61\x66\x74\x65\x72\x55\x70\x64\x61\x74\x65","\x61\x66\x74\x65\x72\x44\x65\x73\x74\x72\x6F\x79","\x6E\x61\x6D\x65","\x6D\x65\x6D\x62\x65\x72\x6E\x61\x6D\x65","\x72\x6F\x6C\x65","\x61\x64\x6D\x69\x6E","\x72\x65\x70\x6F\x72\x74\x5F\x63\x68\x61\x74\x3A\x73\x61\x76\x65","\x65\x6D\x69\x74","\x61\x67\x65\x6E\x74\x69\x64","\x63\x68\x61\x6E\x67\x65\x64","\x72\x65\x70\x6F\x72\x74\x5F\x63\x68\x61\x74\x3A\x61\x73\x73\x69\x67\x6E\x6D\x65\x6E\x74","\x72\x65\x70\x6F\x72\x74\x5F\x63\x68\x61\x74\x3A\x75\x70\x64\x61\x74\x65","\x72\x65\x70\x6F\x72\x74\x5F\x63\x68\x61\x74\x3A\x72\x65\x6D\x6F\x76\x65"];_0xe1d1[0];var ReportChat=require(_0xe1d1[2])[_0xe1d1[1]];exports[_0xe1d1[3]]=function(_0xc910x2){ReportChat[_0xe1d1[4]](function(_0xc910x3){onSave(_0xc910x2,_0xc910x3)});ReportChat[_0xe1d1[5]](function(_0xc910x3){onUpdate(_0xc910x2,_0xc910x3)});ReportChat[_0xe1d1[6]](function(_0xc910x3){onRemove(_0xc910x2,_0xc910x3)});};function onSave(_0xc910x2,_0xc910x3,_0xc910x5){if(_0xc910x2[_0xe1d1[7]]===_0xc910x3[_0xe1d1[8]]||_0xc910x2[_0xe1d1[9]]===_0xe1d1[10]){_0xc910x2[_0xe1d1[12]](_0xe1d1[11],_0xc910x3)}}function onUpdate(_0xc910x2,_0xc910x3,_0xc910x5){if(_0xc910x2[_0xe1d1[7]]===_0xc910x3[_0xe1d1[8]]||_0xc910x2[_0xe1d1[9]]===_0xe1d1[10]){if(_0xc910x3[_0xe1d1[14]](_0xe1d1[13])){_0xc910x2[_0xe1d1[12]](_0xe1d1[15],_0xc910x3)}else {_0xc910x2[_0xe1d1[12]](_0xe1d1[16],_0xc910x3)}}}function onRemove(_0xc910x2,_0xc910x3,_0xc910x5){_0xc910x2[_0xe1d1[12]](_0xe1d1[17],_0xc910x3)}
\ No newline at end of file
+/**
+ * Broadcast updates to client when the model changes
+ */
+
+'use strict';
+
+var ReportChat = require('../../models').ReportChat;
+
+exports.register = function (socket) {
+  ReportChat.afterCreate(function (doc) {
+    onSave(socket, doc);
+  });
+  ReportChat.afterUpdate(function (doc) {
+    onUpdate(socket, doc);
+  });
+  ReportChat.afterDestroy(function (doc) {
+    onRemove(socket, doc);
+  });
+}
+
+function onSave(socket, doc, cb) {
+  if (socket.name === doc.membername || socket.role === 'admin') {
+    socket.emit('report_chat:save', doc);
+  }
+}
+
+function onUpdate(socket, doc, cb) {
+  if (socket.name === doc.membername || socket.role === 'admin') {
+    if (doc.changed('agentid')) {
+      socket.emit('report_chat:assignment', doc);
+    } else {
+      socket.emit('report_chat:update', doc);
+    }
+  }
+}
+
+function onRemove(socket, doc, cb) {
+  socket.emit('report_chat:remove', doc);
+}