Skip to content

A platform for community discussion. Free, open, simple.

FIX: message bus now properly detects log off

Sam9a55a3e8fd3e
diff --git a/app/assets/javascripts/discourse/initializers/message-bus.js.es6 b/app/assets/javascripts/discourse/initializers/message-bus.js.es6
index a0b113765cb..11141b4dc02 100644
--- a/app/assets/javascripts/discourse/initializers/message-bus.js.es6
+++ b/app/assets/javascripts/discourse/initializers/message-bus.js.es6
@@ -1,5 +1,20 @@
// Initialize the message bus to receive messages.
import pageVisible from 'discourse/lib/page-visible';
+import { handleLogoff } from 'discourse/lib/ajax';
+
+function ajax(opts) {
+ if (opts.complete) {
+ let oldComplete = opts.complete;
+ opts.complete = function(xhr, stat) {
+ handleLogoff(xhr);
+ oldComplete(xhr, stat);
+ };
+ } else {
+ opts.complete = handleLogoff;
+ }
+
+ return $.ajax(opts);
+}
export default {
name: "message-bus",
@@ -41,7 +56,7 @@ export default {
if (pageVisible()) {
opts.headers['Discourse-Visible'] = "true";
}
- return $.ajax(opts);
+ return ajax(opts);
};
} else {
@@ -50,7 +65,7 @@ export default {
if (pageVisible()) {
opts.headers['Discourse-Visible'] = "true";
}
- return $.ajax(opts);
+ return ajax(opts);
};
messageBus.baseUrl = Discourse.getURL('/');
diff --git a/app/assets/javascripts/discourse/lib/ajax.js.es6 b/app/assets/javascripts/discourse/lib/ajax.js.es6
index cce7e5dcbab..15e66b3f042 100644
--- a/app/assets/javascripts/discourse/lib/ajax.js.es6
+++ b/app/assets/javascripts/discourse/lib/ajax.js.es6
@@ -13,6 +13,22 @@ export function viewTrackingRequired() {
_trackView = true;
}
+export function handleLogoff(xhr) {
+ if (xhr.getResponseHeader('Discourse-Logged-Out') && !_showingLogout) {
+ _showingLogout = true;
+ const messageBus = Discourse.__container__.lookup('message-bus:main');
+ messageBus.stop();
+ bootbox.dialog(
+ I18n.t("logout"), {label: I18n.t("refresh"), callback: logout},
+ {
+ onEscape: () => logout(),
+ backdrop: 'static'
+ }
+ );
+ }
+};
+
+
/**
Our own $.ajax method. Makes sure the .then method executes in an Ember runloop
for performance reasons. Also automatically adjusts the URL to support installs
@@ -60,19 +76,6 @@ export function ajax() {
args.headers['Discourse-Visible'] = "true";
}
- let handleLogoff = function(xhr) {
- if (xhr.getResponseHeader('Discourse-Logged-Out') && !_showingLogout) {
- _showingLogout = true;
- bootbox.dialog(
- I18n.t("logout"), {label: I18n.t("refresh"), callback: logout},
- {
- onEscape: () => logout(),
- backdrop: 'static'
- }
- );
- }
- };
-
args.success = (data, textStatus, xhr) => {
handleLogoff(xhr);