diff --git a/app/assets/javascripts/discourse/models/post.js.coffee.erb b/app/assets/javascripts/discourse/models/post.js.coffee.erb index 564512e45..038611e7b 100644 --- a/app/assets/javascripts/discourse/models/post.js.coffee.erb +++ b/app/assets/javascripts/discourse/models/post.js.coffee.erb @@ -173,6 +173,27 @@ window.Discourse.Post = Ember.Object.extend Discourse.Presence, loadVersions: (callback) -> $.get "/posts/#{@get('id')}/versions.json", (result) -> callback(result) + + # Whether to show replies directly below + showRepliesBelow: (-> + reply_count = @get('reply_count') + + # We don't show replies if there aren't any + return false if reply_count is 0 + + # Always show replies if the setting `supress_reply_directly_below` is false. + return true unless Discourse.SiteSettings.supress_reply_directly_below + + # Always show replies if there's more than one + return true if reply_count > 1 + + # If we have *exactly* one reply, we have to consider if it's directly below us + return false if @get('topic')?.isReplyDirectlyBelow(@) + + true + + ).property('reply_count') + window.Discourse.Post.reopenClass REGULAR_TYPE: <%= Post::REGULAR %> diff --git a/app/assets/javascripts/discourse/models/topic.js.coffee b/app/assets/javascripts/discourse/models/topic.js.coffee index cba49d52f..30705f4a0 100644 --- a/app/assets/javascripts/discourse/models/topic.js.coffee +++ b/app/assets/javascripts/discourse/models/topic.js.coffee @@ -243,6 +243,18 @@ Discourse.Topic = Discourse.Model.extend Discourse.Presence, newPosts.each (p)-> posts.pushObject(p) unless map[p.get('post_number')] + # Is the reply to a post directly below it? + isReplyDirectlyBelow: (post) -> + posts = @get('posts') + return unless posts + + postBelow = posts[posts.indexOf(post) + 1] + + # If the post directly below's reply_to_post_number is our post number, it's + # considered directly below. + return postBelow?.get('reply_to_post_number') is post.get('post_number') + + window.Discourse.Topic.reopenClass NotificationLevel: diff --git a/app/assets/javascripts/discourse/views/post_menu_view.js.coffee b/app/assets/javascripts/discourse/views/post_menu_view.js.coffee index 75855407f..bf884bbcf 100644 --- a/app/assets/javascripts/discourse/views/post_menu_view.js.coffee +++ b/app/assets/javascripts/discourse/views/post_menu_view.js.coffee @@ -26,15 +26,13 @@ window.Discourse.PostMenuView = Ember.View.extend Discourse.Presence, # Trigger re rendering needsToRender: (-> @rerender() - ).observes('post.deleted_at', 'post.flagsAvailable.@each', 'post.url', 'post.bookmarked', 'post.reply_count', 'post.can_delete') + ).observes('post.deleted_at', 'post.flagsAvailable.@each', 'post.url', 'post.bookmarked', 'post.reply_count', 'post.showRepliesBelow', 'post.can_delete') # Replies Button renderReplies: (post, buffer) -> - return if @get('post.replyFollowing') - + return unless post.get('showRepliesBelow') reply_count = post.get('reply_count') - return if reply_count == 0 buffer.push("