REFACTOR: Remove container from ajax

REFACTOR: Remove container from ajax

diff --git a/app/assets/javascripts/discourse/app/components/d-document.js b/app/assets/javascripts/discourse/app/components/d-document.js
index 2cbe7e8..4264a34 100644
--- a/app/assets/javascripts/discourse/app/components/d-document.js
+++ b/app/assets/javascripts/discourse/app/components/d-document.js
@@ -1,10 +1,14 @@
 import Component from "@ember/component";
 import { inject as service } from "@ember/service";
 import { bind } from "discourse-common/utils/decorators";
+import logout from "discourse/lib/logout";
+import I18n from "I18n";
+import { setLogoffCallback } from "discourse/lib/ajax";
 
 export default Component.extend({
   tagName: "",
   documentTitle: service(),
+  _showingLogout: false,
 
   didInsertElement() {
     this._super(...arguments);
@@ -16,11 +20,13 @@ export default Component.extend({
     this.session.hasFocus = true;
 
     this.appEvents.on("notifications:changed", this, this._updateNotifications);
+    setLogoffCallback(() => this.displayLogoff());
   },
 
   willDestroyElement() {
     this._super(...arguments);
 
+    setLogoffCallback(null);
     document.removeEventListener("visibilitychange", this._focusChanged);
     document.removeEventListener("resume", this._focusChanged);
     document.removeEventListener("freeze", this._focusChanged);
@@ -52,5 +58,22 @@ export default Component.extend({
     } else if (!this.hasFocus) {
       this.documentTitle.setFocus(true);
     }
+  },
+
+  displayLogoff() {
+    if (this._showingLogout) {
+      return;
+    }
+
+    this._showingLogout = true;
+    this.messageBus.stop();
+    bootbox.dialog(
+      I18n.t("logout"),
+      { label: I18n.t("refresh"), callback: logout },
+      {
+        onEscape: () => logout(),
+        backdrop: "static"
+      }
+    );
   }
 });
diff --git a/app/assets/javascripts/discourse/app/lib/ajax.js b/app/assets/javascripts/discourse/app/lib/ajax.js
index 64d2ab9..d21e8a6 100644
--- a/app/assets/javascripts/discourse/app/lib/ajax.js
+++ b/app/assets/javascripts/discourse/app/lib/ajax.js
@@ -1,8 +1,6 @@
 import getURL from "discourse-common/lib/get-url";
-import I18n from "I18n";
 import { run } from "@ember/runloop";
 import userPresent from "discourse/lib/user-presence";
-import logout from "discourse/lib/logout";
 import Session from "discourse/models/session";
 import { Promise } from "rsvp";
 import Site from "discourse/models/site";
@@ -11,7 +9,7 @@ import User from "discourse/models/user";
 
 let _trackView = false;
 let _transientHeader = null;
-let _showingLogout = false;
+let _logoffCallback;
 
 export function setTransientHeader(key, value) {
   _transientHeader = { key, value };
@@ -21,19 +19,13 @@ export function viewTrackingRequired() {
   _trackView = true;
 }
 
+export function setLogoffCallback(cb) {
+  _logoffCallback = cb;
+}
+
 export function handleLogoff(xhr) {
-  if (xhr && 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"
-      }
-    );
+  if (xhr && xhr.getResponseHeader("Discourse-Logged-Out") && _logoffCallback) {
+    _logoffCallback();
   }
 }
 

GitHub sha: ac498ae2

This commit appears in #10480 which was merged by eviltrout.