make message bus more robust to bad inputs, correct issue where notifications channel is not susbcribed

This commit is contained in:
Sam 2013-08-21 09:07:38 +10:00
parent 487788b65b
commit 8a0a097dfb
1 changed files with 5 additions and 2 deletions

View File

@ -70,7 +70,7 @@ Discourse.MessageBus = (function() {
} }
data = {}; data = {};
_.each(callbacks, function(callback) { _.each(callbacks, function(callback) {
data[callback.channel] = callback.last_id === void 0 ? -1 : callback.last_id; data[callback.channel] = callback.last_id;
}); });
gotData = false; gotData = false;
_this.longPoll = $.ajax(Discourse.getURL("/message-bus/") + clientId + "/poll?" + (!shouldLongPoll() || !_this.enableLongPolling ? "dlp=t" : ""), { _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); callback.func(message.data);
} }
if (message.channel === "/__status") { if (message.channel === "/__status") {
if (message.data[callback.channel] !== void 0) { if (message.data[callback.channel] !== undefined) {
callback.last_id = message.data[callback.channel]; callback.last_id = message.data[callback.channel];
} }
} }
@ -125,6 +125,9 @@ Discourse.MessageBus = (function() {
// Subscribe to a channel // Subscribe to a channel
subscribe: function(channel, func, lastId) { subscribe: function(channel, func, lastId) {
if (typeof(lastId) !== "number" || lastId < -1){
lastId = -1;
}
callbacks.push({ callbacks.push({
channel: channel, channel: channel,
func: func, func: func,