From 8a0a097dfb5bd715f9cbddb4a6349c5b3fb5fce9 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 21 Aug 2013 09:07:38 +1000 Subject: [PATCH] make message bus more robust to bad inputs, correct issue where notifications channel is not susbcribed --- app/assets/javascripts/discourse/components/message_bus.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/components/message_bus.js b/app/assets/javascripts/discourse/components/message_bus.js index 817f197ae..6eea12a39 100644 --- a/app/assets/javascripts/discourse/components/message_bus.js +++ b/app/assets/javascripts/discourse/components/message_bus.js @@ -70,7 +70,7 @@ Discourse.MessageBus = (function() { } data = {}; _.each(callbacks, function(callback) { - data[callback.channel] = callback.last_id === void 0 ? -1 : callback.last_id; + data[callback.channel] = callback.last_id; }); gotData = false; _this.longPoll = $.ajax(Discourse.getURL("/message-bus/") + clientId + "/poll?" + (!shouldLongPoll() || !_this.enableLongPolling ? "dlp=t" : ""), { @@ -91,7 +91,7 @@ Discourse.MessageBus = (function() { callback.func(message.data); } if (message.channel === "/__status") { - if (message.data[callback.channel] !== void 0) { + if (message.data[callback.channel] !== undefined) { callback.last_id = message.data[callback.channel]; } } @@ -125,6 +125,9 @@ Discourse.MessageBus = (function() { // Subscribe to a channel subscribe: function(channel, func, lastId) { + if (typeof(lastId) !== "number" || lastId < -1){ + lastId = -1; + } callbacks.push({ channel: channel, func: func,