REFACTOR: Use the session to track assetVersion/requiresRefresh

REFACTOR: Use the session to track assetVersion/requiresRefresh

This saves us having to put the data on Discourse

diff --git a/app/assets/javascripts/discourse/app/app.js b/app/assets/javascripts/discourse/app/app.js
index 9693598..a22244c 100644
--- a/app/assets/javascripts/discourse/app/app.js
+++ b/app/assets/javascripts/discourse/app/app.js
@@ -1,8 +1,6 @@
 /*global Mousetrap:true*/
 import Application from "@ember/application";
-import { computed } from "@ember/object";
 import { buildResolver } from "discourse-common/resolver";
-import discourseComputed from "discourse-common/utils/decorators";
 
 const _pluginCallbacks = [];
 
@@ -62,30 +60,9 @@ const Discourse = Application.extend({
     });
   },
 
-  @discourseComputed("currentAssetVersion", "desiredAssetVersion")
-  requiresRefresh(currentAssetVersion, desiredAssetVersion) {
-    return desiredAssetVersion && currentAssetVersion !== desiredAssetVersion;
-  },
-
   _registerPluginCode(version, code) {
     _pluginCallbacks.push({ version, code });
-  },
-
-  assetVersion: computed({
-    get() {
-      return this.currentAssetVersion;
-    },
-    set(key, val) {
-      if (val) {
-        if (this.currentAssetVersion) {
-          this.set("desiredAssetVersion", val);
-        } else {
-          this.set("currentAssetVersion", val);
-        }
-      }
-      return this.currentAssetVersion;
-    }
-  })
+  }
 });
 
 export default Discourse;
diff --git a/app/assets/javascripts/discourse/app/controllers/preferences/interface.js b/app/assets/javascripts/discourse/app/controllers/preferences/interface.js
index 5d41ab7..8b63f5b 100644
--- a/app/assets/javascripts/discourse/app/controllers/preferences/interface.js
+++ b/app/assets/javascripts/discourse/app/controllers/preferences/interface.js
@@ -205,7 +205,7 @@ export default Controller.extend({
 
           if (this.isiPad) {
             if (safariHacksDisabled() !== this.disableSafariHacks) {
-              Discourse.set("assetVersion", "forceRefresh");
+              this.session.requiresRefresh = true;
             }
             localStorage.setItem(
               "safari-hacks-disabled",
@@ -233,8 +233,7 @@ export default Controller.extend({
       });
 
       // Force refresh when leaving this screen
-      Discourse.set("assetVersion", "forceRefresh");
-
+      this.session.requiresRefresh = true;
       this.set("textSize", newSize);
     }
   }
diff --git a/app/assets/javascripts/discourse/app/initializers/asset-version.js b/app/assets/javascripts/discourse/app/initializers/asset-version.js
index fad499c..ab1a85f 100644
--- a/app/assets/javascripts/discourse/app/initializers/asset-version.js
+++ b/app/assets/javascripts/discourse/app/initializers/asset-version.js
@@ -6,26 +6,32 @@ export default {
   after: "message-bus",
 
   initialize(container) {
-    let timeoutIsSet = false;
+    let timeout;
     const messageBus = container.lookup("message-bus:main");
     if (!messageBus) {
       return;
     }
 
+    let session = container.lookup("session:main");
+    messageBus.subscribe("/refresh_client", () => {
+      session.requiresRefresh = true;
+    });
+
     messageBus.subscribe("/global/asset-version", function(version) {
-      Discourse.set("assetVersion", version);
+      if (session.assetVersion !== version) {
+        session.requiresRefresh = true;
+      }
 
-      if (!timeoutIsSet && Discourse.get("requiresRefresh")) {
+      if (!timeout && session.requiresRefresh) {
         // Since we can do this transparently for people browsing the forum
-        //  hold back the message 24 hours.
-        later(() => {
+        // hold back the message 24 hours.
+        timeout = later(() => {
           bootbox.confirm(I18n.t("assets_changed_confirm"), function(result) {
             if (result) {
               document.location.reload();
             }
           });
         }, 1000 * 60 * 24 * 60);
-        timeoutIsSet = true;
       }
     });
   }
diff --git a/app/assets/javascripts/discourse/app/initializers/subscribe-user-notifications.js b/app/assets/javascripts/discourse/app/initializers/subscribe-user-notifications.js
index af11b97..53c6376 100644
--- a/app/assets/javascripts/discourse/app/initializers/subscribe-user-notifications.js
+++ b/app/assets/javascripts/discourse/app/initializers/subscribe-user-notifications.js
@@ -126,9 +126,6 @@ export default {
       bus.subscribe("/client_settings", data =>
         set(siteSettings, data.name, data.value)
       );
-      bus.subscribe("/refresh_client", data =>
-        Discourse.set("assetVersion", data)
-      );
 
       if (!isTesting()) {
         bus.subscribe(alertChannel(user), data =>
diff --git a/app/assets/javascripts/discourse/app/lib/url.js b/app/assets/javascripts/discourse/app/lib/url.js
index b5b582f..60211f9 100644
--- a/app/assets/javascripts/discourse/app/lib/url.js
+++ b/app/assets/javascripts/discourse/app/lib/url.js
@@ -6,6 +6,7 @@ import LockOn from "discourse/lib/lock-on";
 import { defaultHomepage } from "discourse/lib/utilities";
 import User from "discourse/models/user";
 import { default as getURL, withoutPrefix } from "discourse-common/lib/get-url";
+import Session from "discourse/models/session";
 
 const rewrites = [];
 const TOPIC_REGEXP = /\/t\/([^\/]+)\/(\d+)\/?(\d+)?/;
@@ -211,7 +212,7 @@ const DiscourseURL = EmberObject.extend({
       return;
     }
 
-    if (Discourse.get("requiresRefresh")) {
+    if (Session.currentProp("requiresRefresh")) {
       return redirectTo(getURL(path));
     }
 
diff --git a/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js b/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js
index d8eb01d..adc5c25 100644
--- a/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js
+++ b/app/assets/javascripts/discourse/app/pre-initializers/discourse-bootstrap.js
@@ -70,7 +70,7 @@ export default {
     window.Logster = window.Logster || {};
     window.Logster.enabled = setupData.enableJsErrorReporting === "true";
 
-    app.set("assetVersion", setupData.assetVersion);
+    Session.currentProp("assetVersion", setupData.assetVersion);
 
     Session.currentProp(
       "disableCustomCSS",

GitHub sha: 7cd11bad