Option to supress replies button below a post, when its reply is directly following.

This commit is contained in:
Robin Ward
2013-02-12 14:35:21 -05:00
parent 04c8b20840
commit d7f3241285
5 changed files with 39 additions and 6 deletions

View File

@@ -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 %>

View File

@@ -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:

View File

@@ -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("<button class='show-replies' data-action='replies'>")
buffer.push("<span class='badge-posts'>#{reply_count}</span>")
@@ -97,7 +95,6 @@ window.Discourse.PostMenuView = Ember.View.extend Discourse.Presence,
clickReply: -> @get('controller').replyToPost(@get('post'))
# Bookmark button
renderBookmark: (post, buffer) ->
return unless Discourse.get('currentUser')