REFACTOR: Remove `Discourse.Session` constants
This commit is contained in:
parent
7ac2a55588
commit
291572a97a
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
})
|
||||
|
|
|
@ -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(() => {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -27,13 +27,15 @@
|
|||
I18n.defaultLocale = setupData.defaultLocale;
|
||||
Discourse.start();
|
||||
Discourse.set("assetVersion", setupData.assetVersion);
|
||||
Discourse.Session.currentProp(
|
||||
|
||||
let Session = require("discourse/models/session").default;
|
||||
Session.currentProp(
|
||||
"disableCustomCSS",
|
||||
setupData.disableCustomCss === "true"
|
||||
);
|
||||
|
||||
if (setupData.safeMode) {
|
||||
Discourse.Session.currentProp("safe_mode", setupData.safeMode);
|
||||
Session.currentProp("safe_mode", setupData.safeMode);
|
||||
}
|
||||
|
||||
Discourse.HighlightJSPath = setupData.highlightJsPath;
|
||||
|
|
|
@ -117,7 +117,9 @@ QUnit.testStart(function(ctx) {
|
|||
Discourse.SiteSettings = dup(Discourse.SiteSettingsOriginal);
|
||||
Discourse.BaseUri = "";
|
||||
Discourse.BaseUrl = "http://localhost:3000";
|
||||
Discourse.Session.resetCurrent();
|
||||
|
||||
let Session = require("discourse/models/session").default;
|
||||
Session.resetCurrent();
|
||||
Discourse.User.resetCurrent();
|
||||
resetSite(Discourse.SiteSettings);
|
||||
|
||||
|
|
Loading…
Reference in New Issue