FIX: message bus now properly detects log off
Previously under some conditions message bus could continue firing even if a user is logged off. This change ensures that under all conditions once server informs client of a log off, client stops talking to server
This commit is contained in:
parent
98d880b67a
commit
9a55a3e8fd
|
@ -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('/');
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue