REFACTOR: Remove `Discourse.Session` constants

REFACTOR: Remove Discourse.Session constants

diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 290f920789..fa5ef28880 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -13,6 +13,9 @@
 //= require ./discourse/lib/utilities
 //= require ./discourse/lib/page-visible
 //= require ./discourse/lib/logout
+//= require ./discourse/mixins/singleton
+//= require ./discourse/models/rest
+//= require ./discourse/models/session
 //= require ./discourse/lib/ajax
 //= require ./discourse/lib/text
 //= require ./discourse/lib/hash
@@ -34,7 +37,6 @@
 //= require ./discourse/mixins/scrolling
 //= require ./discourse/lib/ajax-error
 //= require ./discourse/models/model
-//= require ./discourse/models/rest
 //= require ./discourse/models/result-set
 //= require ./discourse/models/store
 //= require ./discourse/models/action-summary
diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6
index 7f2708a789..1a67f6e0ed 100644
--- a/app/assets/javascripts/discourse/controllers/topic.js.es6
+++ b/app/assets/javascripts/discourse/controllers/topic.js.es6
@@ -447,9 +447,7 @@ export default Controller.extend(bufferedProperty("model"), {
         : "/";
       ajax("/t/" + topic.get("id") + "/timings.json?last=1", { type: "DELETE" })
         .then(() => {
-          const highestSeenByTopic = Discourse.Session.currentProp(
-            "highestSeenByTopic"
-          );
+          const highestSeenByTopic = this.session.get("highestSeenByTopic");
           highestSeenByTopic[topic.get("id")] = null;
           DiscourseURL.routeTo(goToPath);
         })
diff --git a/app/assets/javascripts/discourse/lib/ajax.js.es6 b/app/assets/javascripts/discourse/lib/ajax.js.es6
index 40fd85d686..7b7d9fda98 100644
--- a/app/assets/javascripts/discourse/lib/ajax.js.es6
+++ b/app/assets/javascripts/discourse/lib/ajax.js.es6
@@ -1,6 +1,7 @@
 import { run } from "@ember/runloop";
 import pageVisible from "discourse/lib/page-visible";
 import logout from "discourse/lib/logout";
+import Session from "discourse/models/session";
 import { Promise } from "rsvp";
 
 let _trackView = false;
@@ -44,7 +45,7 @@ function handleRedirect(data) {
 
 export function updateCsrfToken() {
   return ajax("/session/csrf").then(result => {
-    Discourse.Session.currentProp("csrfToken", result.csrf);
+    Session.currentProp("csrfToken", result.csrf);
   });
 }
 
@@ -120,7 +121,7 @@ export function ajax() {
       // note: for bad CSRF we don't loop an extra request right away.
       //  this allows us to eliminate the possibility of having a loop.
       if (xhr.status === 403 && xhr.responseText === '["BAD CSRF"]') {
-        Discourse.Session.current().set("csrfToken", null);
+        Session.current().set("csrfToken", null);
       }
 
       // If it's a parsererror, don't reject
@@ -162,7 +163,7 @@ export function ajax() {
     args.type &&
     args.type.toUpperCase() !== "GET" &&
     url !== Discourse.getURL("/clicks/track") &&
-    !Discourse.Session.currentProp("csrfToken")
+    !Session.currentProp("csrfToken")
   ) {
     promise = new Promise((resolve, reject) => {
       ajaxObj = updateCsrfToken().then(() => {
diff --git a/app/assets/javascripts/discourse/models/login-method.js.es6 b/app/assets/javascripts/discourse/models/login-method.js.es6
index 12a4969768..040e175e74 100644
--- a/app/assets/javascripts/discourse/models/login-method.js.es6
+++ b/app/assets/javascripts/discourse/models/login-method.js.es6
@@ -2,6 +2,7 @@ import discourseComputed from "discourse-common/utils/decorators";
 import EmberObject from "@ember/object";
 import { updateCsrfToken } from "discourse/lib/ajax";
 import { Promise } from "rsvp";
+import Session from "discourse/models/session";
 
 const LoginMethod = EmberObject.extend({
   @discourseComputed
@@ -52,7 +53,7 @@ LoginMethod.reopenClass({
 
       const input = document.createElement("input");
       input.setAttribute("name", "authenticity_token");
-      input.setAttribute("value", Discourse.Session.currentProp("csrfToken"));
+      input.setAttribute("value", Session.currentProp("csrfToken"));
       form.appendChild(input);
 
       document.body.appendChild(form);
diff --git a/app/assets/javascripts/discourse/models/topic-list.js.es6 b/app/assets/javascripts/discourse/models/topic-list.js.es6
index bec760fd69..b0ec31a834 100644
--- a/app/assets/javascripts/discourse/models/topic-list.js.es6
+++ b/app/assets/javascripts/discourse/models/topic-list.js.es6
@@ -6,6 +6,7 @@ import Model from "discourse/models/model";
 import { getOwner } from "discourse-common/lib/get-owner";
 import { Promise } from "rsvp";
 import Category from "discourse/models/category";
+import Session from "discourse/models/session";
 
 // Whether to show the category badge in topic lists
 function displayCategoryInList(site, category) {
@@ -93,7 +94,7 @@ const TopicList = RestModel.extend({
             more_topics_url: result.topic_list.more_topics_url
           });
 
-          Discourse.Session.currentProp("topicList", this);
+          Session.currentProp("topicList", this);
           return this.more_topics_url;
         }
       });
@@ -123,7 +124,7 @@ const TopicList = RestModel.extend({
         i++;
       });
 
-      if (storeInSession) Discourse.Session.currentProp("topicList", this);
+      if (storeInSession) Session.currentProp("topicList", this);
     });
   }
 });
diff --git a/app/assets/javascripts/discourse/models/topic.js.es6 b/app/assets/javascripts/discourse/models/topic.js.es6
index ad9918b8a9..ca41597cfd 100644
--- a/app/assets/javascripts/discourse/models/topic.js.es6
+++ b/app/assets/javascripts/discourse/models/topic.js.es6
@@ -19,6 +19,7 @@ import {
   on
 } from "discourse-common/utils/decorators";
 import Category from "discourse/models/category";
+import Session from "discourse/models/session";
 
 export function loadTopicView(topic, args) {
   const data = _.merge({}, args);
@@ -306,7 +307,7 @@ const Topic = RestModel.extend({
   // So take what the browser has seen into consideration.
   @discourseComputed("new_posts", "id")
   displayNewPosts(newPosts, id) {
-    const highestSeen = Discourse.Session.currentProp("highestSeenByTopic")[id];
+    const highestSeen = Session.currentProp("highestSeenByTopic")[id];
     if (highestSeen) {
       const delta = highestSeen - this.last_read_post_number;
       if (delta > 0) {
diff --git a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6 b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6
index 5d0a576005..34847b8725 100644
--- a/app/assets/javascripts/discourse/routes/build-topic-route.js.es6
+++ b/app/assets/javascripts/discourse/routes/build-topic-route.js.es6
@@ -1,6 +1,7 @@
 import DiscourseRoute from "discourse/routes/discourse";
 import { queryParams } from "discourse/controllers/discovery-sortable";
 import { defaultHomepage } from "discourse/lib/utilities";
+import Session from "discourse/models/session";
 
 // A helper to build a topic route for a filter
 function filterQueryParams(params, defaultParams) {
@@ -19,7 +20,7 @@ function filterQueryParams(params, defaultParams) {
 function findTopicList(store, tracking, filter, filterParams, extras) {
   extras = extras || {};
   return new Promise(function(resolve) {
-    const session = Discourse.Session.current();
+    const session = Session.current();
 
     if (extras.cached) {
       const cachedList = session.get("topicList");
@@ -62,7 +63,7 @@ function findTopicList(store, tracking, filter, filterParams, extras) {
       tracking.sync(list, list.filter);
       tracking.trackIncoming(list.filter);
     }
-    Discourse.Session.currentProp("topicList", list);
+    Session.currentProp("topicList", list);
     if (list.topic_list && list.topic_list.top_tags) {
       Discourse.Site.currentProp("top_tags", list.topic_list.top_tags);
     }

[... diff too long, it was truncated ...]

GitHub sha: 291572a9