[CORD-2277] Sending event when model is deleted
Change-Id: I4ff5376dc4d707e0b59b5c852c89b98f940c7e40
diff --git a/src/controllers/redis.js b/src/controllers/redis.js
index a051e36..7e86000 100644
--- a/src/controllers/redis.js
+++ b/src/controllers/redis.js
@@ -46,18 +46,28 @@
});
client.on('pmessage', function (pattern, channel, message) {
- logger.log('warn', 'sub channel ' + channel + ': ' + message);
+ if (channel === 'Diag') {
+ return;
+ }
+
let msg;
try {
msg = JSON.parse(message);
// TODO find the user that needs to be notified for msg.object update
- socket.emit('event', {model: channel, msg: msg});
}
catch(e) {
// send the event also if it is not JSON
msg = message;
- socket.emit('event', {model: channel, msg: msg});
+ }
+
+ if (msg.deleted) {
+ logger.log('warn', 'Remove on: ' + channel + ': ' + message);
+ socket.emit('remove', {model: channel, msg: msg, deleted: true});
+ }
+ else {
+ logger.log('warn', 'Update on: ' + channel + ': ' + message);
+ socket.emit('update', {model: channel, msg: msg});
}
});