A platform for community discussion. Free, open, simple.
REFACTOR: Migrate `Discourse.Post` to imports
Robin Ward7e44065bcbd4
diff --git a/app/assets/javascripts/discourse/controllers/history.js.es6 b/app/assets/javascripts/discourse/controllers/history.js.es6index 79203ed563c..7d68d2ab661 100644--- a/app/assets/javascripts/discourse/controllers/history.js.es6+++ b/app/assets/javascripts/discourse/controllers/history.js.es6@@ -7,6 +7,7 @@ import { propertyGreaterThan, propertyLessThan } from "discourse/lib/computed";import { on, observes } from "discourse-common/utils/decorators";import { sanitizeAsync } from "discourse/lib/text";import { iconHTML } from "discourse-common/lib/icon-library";+import Post from "discourse/models/post";function customTagArray(fieldName) {return Ember.computed(fieldName, function() {@@ -59,19 +60,19 @@ export default Controller.extend(ModalFunctionality, {refresh(postId, postVersion) {this.set("loading", true);- Discourse.Post.loadRevision(postId, postVersion).then(result => {+ Post.loadRevision(postId, postVersion).then(result => {this.setProperties({ loading: false, model: result });});},hide(postId, postVersion) {- Discourse.Post.hideRevision(postId, postVersion).then(() =>+ Post.hideRevision(postId, postVersion).then(() =>this.refresh(postId, postVersion));},show(postId, postVersion) {- Discourse.Post.showRevision(postId, postVersion).then(() =>+ Post.showRevision(postId, postVersion).then(() =>this.refresh(postId, postVersion));},diff --git a/app/assets/javascripts/discourse/models/post.js.es6 b/app/assets/javascripts/discourse/models/post.js.es6index 83a18d9a12f..b49aaea7474 100644--- a/app/assets/javascripts/discourse/models/post.js.es6+++ b/app/assets/javascripts/discourse/models/post.js.es6@@ -16,7 +16,7 @@ import Composer from "discourse/models/composer";import { Promise } from "rsvp";const Post = RestModel.extend({- // TODO: Remove this once one instantiate all `Discourse.Post` models via the store.+ // TODO: Remove this once one instantiate all `Post` models via the store.siteSettings: Ember.computed({get() {return Discourse.SiteSettings;@@ -320,7 +320,7 @@ const Post = RestModel.extend({// need to wait to hear back from server (stuff may not be loaded)- return Discourse.Post.updateBookmark(this.id, this.bookmarked)+ return Post.updateBookmark(this.id, this.bookmarked).then(result => {this.set("topic.bookmarked", result.topic_bookmarked);this.appEvents.trigger("page:bookmark-post-toggled", this);@@ -417,7 +417,7 @@ Post.reopenClass({loadQuote(postId) {return ajax(`/posts/${postId}.json`).then(result => {- const post = Discourse.Post.create(result);+ const post = Post.create(result);return Quote.build(post, post.raw, { raw: true, full: true });});},diff --git a/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb b/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rbindex 382417b8b4b..c129e660017 100644--- a/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb+++ b/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb@@ -91,8 +91,7 @@ JS"discourse/models/site","discourse/models/user","discourse/models/session",- "discourse/models/model",- "discourse/models/post"+ "discourse/models/model"])diff --git a/test/javascripts/models/composer-test.js.es6 b/test/javascripts/models/composer-test.js.es6index 78c823b2bec..cd3135b74f6 100644--- a/test/javascripts/models/composer-test.js.es6+++ b/test/javascripts/models/composer-test.js.es6@@ -2,6 +2,7 @@ import EmberObject from "@ember/object";import { currentUser } from "helpers/qunit-helpers";import AppEvents from "discourse/services/app-events";import Composer from "discourse/models/composer";+import Post from "discourse/models/post";import createStore from "helpers/create-store";QUnit.module("model:composer");@@ -247,7 +248,7 @@ QUnit.test("editingFirstPost", assert => {const composer = createComposer();assert.ok(!composer.get("editingFirstPost"), "it's false by default");- const post = Discourse.Post.create({ id: 123, post_number: 2 });+ const post = Post.create({ id: 123, post_number: 2 });composer.setProperties({ post: post, action: Composer.EDIT });assert.ok(!composer.get("editingFirstPost"),@@ -265,7 +266,7 @@ QUnit.test("clearState", assert => {const composer = createComposer({originalText: "asdf",reply: "asdf2",- post: Discourse.Post.create({ id: 1 }),+ post: Post.create({ id: 1 }),title: "wat"});@@ -329,7 +330,7 @@ QUnit.test("Title length for static page topics as admin", assert => {Discourse.SiteSettings.max_topic_title_length = 10;const composer = createComposer();- const post = Discourse.Post.create({+ const post = Post.create({id: 123,post_number: 2,static_doc: truediff --git a/test/javascripts/models/post-stream-test.js.es6 b/test/javascripts/models/post-stream-test.js.es6index eb99d811afb..49b6018e203 100644--- a/test/javascripts/models/post-stream-test.js.es6+++ b/test/javascripts/models/post-stream-test.js.es6@@ -1,7 +1,8 @@-QUnit.module("model:post-stream");-+import Post from "discourse/models/post";import createStore from "helpers/create-store";+QUnit.module("model:post-stream");+const buildStream = function(id, stream) {const store = createStore();const topic = store.createRecord("topic", { id, chunk_size: 5 });@@ -173,7 +174,7 @@ QUnit.test("updateFromJson", assert => {});assert.equal(postStream.get("posts.length"), 1, "it loaded the posts");- assert.containsInstance(postStream.get("posts"), Discourse.Post);+ assert.containsInstance(postStream.get("posts"), Post);assert.equal(postStream.get("extra_property"), 12);});diff --git a/test/javascripts/models/post-test.js.es6 b/test/javascripts/models/post-test.js.es6index afe69d03ad0..5a7aa345202 100644--- a/test/javascripts/models/post-test.js.es6+++ b/test/javascripts/models/post-test.js.es6@@ -1,7 +1,9 @@-QUnit.module("Discourse.Post");+import Post from "discourse/models/post";++QUnit.module("model: Post");var buildPost = function(args) {- return Discourse.Post.create(+ return Post.create(_.merge({id: 1,@@ -14,13 +16,13 @@ var buildPost = function(args) {};QUnit.test("defaults", assert => {- var post = Discourse.Post.create({ id: 1 });+ var post = Post.create({ id: 1 });assert.blank(post.get("deleted_at"), "it has no deleted_at by default");assert.blank(post.get("deleted_by"), "there is no deleted_by by default");});QUnit.test("new_user", assert => {- var post = Discourse.Post.create({ trust_level: 0 });+ var post = Post.create({ trust_level: 0 });assert.ok(post.get("new_user"), "post is from a new user");post.set("trust_level", 1);@@ -28,7 +30,7 @@ QUnit.test("new_user", assert => {});QUnit.test("firstPost", assert => {- var post = Discourse.Post.create({ post_number: 1 });+ var post = Post.create({ post_number: 1 });assert.ok(post.get("firstPost"), "it's the first post");post.set("post_number", 10);@@ -36,13 +38,13 @@ QUnit.test("firstPost", assert => {});QUnit.test("updateFromPost", assert => {- var post = Discourse.Post.create({+ var post = Post.create({post_number: 1,raw: "hello world"});post.updateFromPost(- Discourse.Post.create({+ Post.create({raw: "different raw",wat: function() {return 123;