diff --git a/app/assets/javascripts/discourse/models/composer.js.es6 b/app/assets/javascripts/discourse/models/composer.js.es6 index 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.es6 index 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 `${ + this.attrs.fancy_title + }`; + } return this.attrs.fancy_title; } diff --git a/app/assets/stylesheets/common/base/menu-panel.scss b/app/assets/stylesheets/common/base/menu-panel.scss index 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.scss index 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.scss index 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.rb index cd01e20e951..b03bec874be 100644 --- a/lib/new_post_manager.rb +++ b/lib/new_post_manager.rb @@ -22,7 +22,7 @@ class NewPostManager end def self.clear_handlers! - @sorted_handlers = [{ priority: 0, proc: method(:default_handler) }] + @sorted_handlers = [] end def self.add_handler(priority = 0, &block) @@ -178,22 +178,17 @@ class NewPostManager return result end - # 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 - - false end - 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_post end # Enqueue this post diff --git a/lib/post_creator.rb b/lib/post_creator.rb index 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 PostCreator def create_topic return if @topic begin - 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.create rescue ActiveRecord::Rollback rollback_from_errors!(topic_creator) diff --git a/lib/topic_creator.rb b/lib/topic_creator.rb index c45a870599a..e46f2f6e3ac 100644 --- a/lib/topic_creator.rb +++ b/lib/topic_creator.rb @@ -37,6 +37,9 @@ class TopicCreator def create topic = Topic.new(setup_topic_params) setup_tags(topic) + if fields = @opts[:custom_fields] + topic.custom_fields = fields + end DiscourseEvent.trigger(:before_create_topic, topic, self) diff --git a/spec/components/new_post_manager_spec.rb b/spec/components/new_post_manager_spec.rb index 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 do handler = -> { nil } NewPostManager.add_handler(&handler) - expect(NewPostManager.handlers).to eq([default_handler, handler]) + expect(NewPostManager.handlers).to eq([handler]) end it "can be added in high priority" do @@ -223,7 +223,7 @@ describe NewPostManager do NewPostManager.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]) end end diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index 90dcaf3f4cf..c4decf5fa83 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -54,6 +54,11 @@ describe PostCreator do expect { 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" do it "omits reply to post number if received on a new topic" do p = PostCreator.new(user, basic_topic_params.merge(reply_to_post_number: 3)).create