From a819a26f34b183cbf3fb1fc3035d80ad6ceffa24 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 28 Mar 2013 16:40:54 -0400 Subject: [PATCH] BUGFIX: New status posts weren't using PostCreator --- .../javascripts/discourse/components/message_bus.js | 8 ++------ .../discourse/controllers/topic_controller.js | 1 + app/assets/javascripts/discourse/views/topic_view.js | 10 +++++----- app/models/topic.rb | 8 ++++++-- lib/post_creator.rb | 3 +++ 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/discourse/components/message_bus.js b/app/assets/javascripts/discourse/components/message_bus.js index c38cb9f4e..d7f4f8625 100644 --- a/app/assets/javascripts/discourse/components/message_bus.js +++ b/app/assets/javascripts/discourse/components/message_bus.js @@ -102,12 +102,8 @@ Discourse.MessageBus = (function() { if (failCount > 2) { interval = interval * failCount; } else if (isHidden()) { - /* slowning down stuff a lot when hidden - */ - - /* we will need to add a lot of fine tuning here - */ - + // slowning down stuff a lot when hidden + // we will need to add a lot of fine tuning here interval = interval * 4; } if (interval > _this.maxPollInterval) { diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index a2d6c6757..b5e1caaa5 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -309,6 +309,7 @@ Discourse.TopicController = Discourse.ObjectController.extend({ })) { return; } + topic.set('posts_count', topic.get('posts_count') + 1); topic.set('highest_post_number', data.post_number); topic.set('last_poster', data.user); diff --git a/app/assets/javascripts/discourse/views/topic_view.js b/app/assets/javascripts/discourse/views/topic_view.js index fe7c61d7f..95bd306f1 100644 --- a/app/assets/javascripts/discourse/views/topic_view.js +++ b/app/assets/javascripts/discourse/views/topic_view.js @@ -350,11 +350,11 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, { }, nonUrgentPositionUpdate: Discourse.debounce(function(opts){ - var screenTrack = this.get('screenTrack'); - if(opts.userActive && screenTrack) { - screenTrack.scrolled(); - } - this.set('controller.currentPost', opts.currentPost); + var screenTrack = this.get('screenTrack'); + if(opts.userActive && screenTrack) { + screenTrack.scrolled(); + } + this.set('controller.currentPost', opts.currentPost); },500), scrolled: function(){ diff --git a/app/models/topic.rb b/app/models/topic.rb index 3d3388ebb..adbc2c84c 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -322,12 +322,16 @@ class Topic < ActiveRecord::Base def add_moderator_post(user, text, opts={}) new_post = nil Topic.transaction do - new_post = posts.create(user: user, raw: text, post_type: Post.types[:moderator_action], no_bump: opts[:bump].blank?) + creator = PostCreator.new(user, + raw: text, + post_type: Post.types[:moderator_action], + no_bump: opts[:bump].blank?, + topic_id: self.id) + new_post = creator.create increment!(:moderator_posts_count) new_post end - if new_post.present? # If we are moving posts, we want to insert the moderator post where the previous posts were # in the stream, not at the end. diff --git a/lib/post_creator.rb b/lib/post_creator.rb index 1c91e803d..e352f433d 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -77,6 +77,9 @@ class PostCreator post = topic.posts.new(raw: @opts[:raw], user: @user, reply_to_post_number: @opts[:reply_to_post_number]) + + post.post_type = @opts[:post_type] if @opts[:post_type].present? + post.no_bump = @opts[:no_bump] if @opts[:no_bump].present? post.extract_quoted_post_numbers post.image_sizes = @opts[:image_sizes] if @opts[:image_sizes].present?