A platform for community discussion. Free, open, simple.
DEV: Improve support for plugins. (#7332)
Dan Ungureanuda39d66e8333
diff --git a/app/assets/javascripts/discourse/models/composer.js.es6 b/app/assets/javascripts/discourse/models/composer.js.es6index 6328b9477c6..620231cf7b2 100644--- a/app/assets/javascripts/discourse/models/composer.js.es6+++ b/app/assets/javascripts/discourse/models/composer.js.es6@@ -724,6 +724,7 @@ const Composer = RestModel.extend({}const props = {+ topic_id: this.topic.id,raw: this.reply,raw_old: this.editConflict ? null : this.originalText,edit_reason: opts.editReason,diff --git a/app/assets/javascripts/discourse/widgets/notification-item.js.es6 b/app/assets/javascripts/discourse/widgets/notification-item.js.es6index 93e1315031f..a298e1ab938 100644--- a/app/assets/javascripts/discourse/widgets/notification-item.js.es6+++ b/app/assets/javascripts/discourse/widgets/notification-item.js.es6@@ -85,6 +85,11 @@ createWidget("notification-item", {}if (this.attrs.fancy_title) {+ if (this.attrs.topic_id) {+ return `<span data-topic-id="${this.attrs.topic_id}">${+ this.attrs.fancy_title+ }</span>`;+ }return this.attrs.fancy_title;}diff --git a/app/assets/stylesheets/common/base/menu-panel.scss b/app/assets/stylesheets/common/base/menu-panel.scssindex 3c49e597ed1..edb8a16ad7a 100644--- a/app/assets/stylesheets/common/base/menu-panel.scss+++ b/app/assets/stylesheets/common/base/menu-panel.scss@@ -169,7 +169,7 @@display: none;}- span {+ span:first-child {color: $primary;}diff --git a/app/assets/stylesheets/common/base/user.scss b/app/assets/stylesheets/common/base/user.scssindex 032a427d04a..676baa76324 100644--- a/app/assets/stylesheets/common/base/user.scss+++ b/app/assets/stylesheets/common/base/user.scss@@ -671,7 +671,7 @@margin-right: 0.5em;}- span {+ span:first-child {color: $primary;}diff --git a/app/assets/stylesheets/common/components/user-stream-item.scss b/app/assets/stylesheets/common/components/user-stream-item.scssindex 99afbdf9ef7..aff93ede1fb 100644--- a/app/assets/stylesheets/common/components/user-stream-item.scss+++ b/app/assets/stylesheets/common/components/user-stream-item.scss@@ -102,7 +102,7 @@p {display: inline-block;- span {+ span:first-child {color: $primary;}}diff --git a/lib/new_post_manager.rb b/lib/new_post_manager.rbindex cd01e20e951..b03bec874be 100644--- a/lib/new_post_manager.rb+++ b/lib/new_post_manager.rb@@ -22,7 +22,7 @@ class NewPostManagerenddef self.clear_handlers!- @sorted_handlers = [{ priority: 0, proc: method(:default_handler) }]+ @sorted_handlers = []enddef self.add_handler(priority = 0, &block)@@ -178,22 +178,17 @@ class NewPostManagerreturn resultend- # We never queue private messages- return perform_create_post if @args[:archetype] == Archetype.private_message-- if args[:topic_id] && Topic.where(id: args[:topic_id], archetype: Archetype.private_message).exists?- return perform_create_post- end-# Perform handlers until one returns a result- handled = NewPostManager.handlers.any? do |handler|+ NewPostManager.handlers.any? do |handler|result = handler.call(self)return result if result-- falseend- perform_create_post unless handled+ # We never queue private messages+ return perform_create_post if @args[:archetype] == Archetype.private_message ||+ (args[:topic_id] && Topic.where(id: args[:topic_id], archetype: Archetype.private_message).exists?)++ NewPostManager.default_handler(self) || perform_create_postend# Enqueue this postdiff --git a/lib/post_creator.rb b/lib/post_creator.rbindex 95363cd2043..70f60c9039a 100644--- a/lib/post_creator.rb+++ b/lib/post_creator.rb@@ -56,6 +56,7 @@ class PostCreator# pinned_at - Topic pinned time (optional)# pinned_globally - Is the topic pinned globally (optional)# shared_draft - Is the topic meant to be a shared draft+ # topic_opts - Options to be overwritten for topic#def initialize(user, opts)# TODO: we should reload user in case it is tainted, should take in a user_id as opposed to user@@ -410,7 +411,8 @@ class PostCreatordef create_topicreturn if @topicbegin- topic_creator = TopicCreator.new(@user, guardian, @opts)+ opts = @opts[:topic_opts] ? @opts.merge(@opts[:topic_opts]) : @opts+ topic_creator = TopicCreator.new(@user, guardian, opts)@topic = topic_creator.createrescue ActiveRecord::Rollbackrollback_from_errors!(topic_creator)diff --git a/lib/topic_creator.rb b/lib/topic_creator.rbindex c45a870599a..e46f2f6e3ac 100644--- a/lib/topic_creator.rb+++ b/lib/topic_creator.rb@@ -37,6 +37,9 @@ class TopicCreatordef createtopic = Topic.new(setup_topic_params)setup_tags(topic)+ if fields = @opts[:custom_fields]+ topic.custom_fields = fields+ endDiscourseEvent.trigger(:before_create_topic, topic, self)diff --git a/spec/components/new_post_manager_spec.rb b/spec/components/new_post_manager_spec.rbindex 6c87345a0da..269ebcbb500 100644--- a/spec/components/new_post_manager_spec.rb+++ b/spec/components/new_post_manager_spec.rb@@ -212,7 +212,7 @@ describe NewPostManager dohandler = -> { nil }NewPostManager.add_handler(&handler)- expect(NewPostManager.handlers).to eq([default_handler, handler])+ expect(NewPostManager.handlers).to eq([handler])endit "can be added in high priority" do@@ -223,7 +223,7 @@ describe NewPostManager doNewPostManager.add_handler(100, &a)NewPostManager.add_handler(50, &b)NewPostManager.add_handler(101, &c)- expect(NewPostManager.handlers).to eq([c, a, b, default_handler])+ expect(NewPostManager.handlers).to eq([c, a, b])endenddiff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rbindex 90dcaf3f4cf..c4decf5fa83 100644--- a/spec/components/post_creator_spec.rb+++ b/spec/components/post_creator_spec.rb@@ -54,6 +54,11 @@ describe PostCreator doexpect { creator.create }.to raise_error(Discourse::InvalidAccess)end+ it "can be created with custom fields" do+ post = PostCreator.create(user, basic_topic_params.merge(topic_opts: { custom_fields: { hello: "world" } }))+ expect(post.topic.custom_fields).to eq("hello" => "world")+ end+context "reply to post number" doit "omits reply to post number if received on a new topic" dop = PostCreator.new(user, basic_topic_params.merge(reply_to_post_number: 3)).create