From e57ddcf2767c1de95340911f34ded4a88bee5a0a Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 14 Nov 2013 16:37:50 +1100 Subject: [PATCH] remove discourse dependency from message bus --- app/assets/javascripts/discourse.js | 2 ++ app/assets/javascripts/discourse/lib/message_bus.js | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse.js b/app/assets/javascripts/discourse.js index b924a0e09..ec15835b1 100644 --- a/app/assets/javascripts/discourse.js +++ b/app/assets/javascripts/discourse.js @@ -190,6 +190,8 @@ Discourse = Ember.Application.createWithMixins(Discourse.Ajax, { var bus = Discourse.MessageBus; bus.callbackInterval = Discourse.SiteSettings.polling_interval; bus.enableLongPolling = true; + bus.baseUrl = Discourse.getURL("/"); + if (user.admin || user.moderator) { bus.subscribe("/flagged_counts", function(data) { user.set('site_flagged_posts_count', data.total); diff --git a/app/assets/javascripts/discourse/lib/message_bus.js b/app/assets/javascripts/discourse/lib/message_bus.js index 6eea12a39..fe0279f91 100644 --- a/app/assets/javascripts/discourse/lib/message_bus.js +++ b/app/assets/javascripts/discourse/lib/message_bus.js @@ -9,7 +9,7 @@ **/ Discourse.MessageBus = (function() { // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript - var callbacks, clientId, failCount, interval, shouldLongPoll, queue, responseCallbacks, uniqueId; + var callbacks, clientId, failCount, interval, shouldLongPoll, queue, responseCallbacks, uniqueId, baseUrl; var me; uniqueId = function() { @@ -27,6 +27,7 @@ Discourse.MessageBus = (function() { queue = []; interval = null; failCount = 0; + baseUrl = "/"; var isHidden = function() { if (document.hidden !== void 0) { @@ -38,8 +39,8 @@ Discourse.MessageBus = (function() { } else if (document.mozHidden !== void 0) { return document.mozHidden; } else { - // fallback to problamatic window.focus - return !Discourse.get('hasFocus'); + // problamatic fallback + return !document.hasFocus; } }; @@ -55,6 +56,7 @@ Discourse.MessageBus = (function() { clientId: clientId, alwaysLongPoll: false, stop: false, + baseUrl: baseUrl, // Start polling start: function(opts) { @@ -73,7 +75,7 @@ Discourse.MessageBus = (function() { data[callback.channel] = callback.last_id; }); gotData = false; - _this.longPoll = $.ajax(Discourse.getURL("/message-bus/") + clientId + "/poll?" + (!shouldLongPoll() || !_this.enableLongPolling ? "dlp=t" : ""), { + _this.longPoll = $.ajax(baseUrl + "message-bus/" + clientId + "/poll?" + (!shouldLongPoll() || !_this.enableLongPolling ? "dlp=t" : ""), { data: data, cache: false, dataType: 'json',