FIX: only show 'defer flags' when there are active flags on the post

This commit is contained in:
Régis Hanol
2014-08-04 17:29:01 +02:00
parent cb0ecd9ff1
commit 2e134742d4
4 changed files with 72 additions and 14 deletions

View File

@@ -188,7 +188,9 @@ class TopicView
end
def has_deleted?
@predelete_filtered_posts.with_deleted.where("deleted_at IS NOT NULL").exists?
@predelete_filtered_posts.with_deleted
.where("posts.deleted_at IS NOT NULL")
.exists?
end
def topic_user
@@ -199,7 +201,11 @@ class TopicView
end
def post_counts_by_user
@post_counts_by_user ||= Post.where(topic_id: @topic.id).group(:user_id).order('count_all desc').limit(24).count
@post_counts_by_user ||= Post.where(topic_id: @topic.id)
.group(:user_id)
.order("count_all DESC")
.limit(24)
.count
end
def participants
@@ -214,6 +220,10 @@ class TopicView
@all_post_actions ||= PostAction.counts_for(@posts, @user)
end
def all_active_flags
@all_active_flags ||= PostAction.active_flags_counts_for(@posts)
end
def links
@links ||= TopicLink.topic_map(guardian, @topic.id)
end
@@ -282,8 +292,7 @@ class TopicView
def filter_posts_by_ids(post_ids)
# TODO: Sort might be off
@posts = Post.where(id: post_ids, topic_id: @topic.id)
.includes(:user)
.includes(:reply_to_user)
.includes(:user, :reply_to_user)
.order('sort_order')
@posts = @posts.with_deleted if @guardian.can_see_deleted_posts?
@posts
@@ -316,7 +325,6 @@ class TopicView
end
def setup_filtered_posts
# Certain filters might leave gaps between posts. If that's true, we can return a gap structure
@contains_gaps = false
@filtered_posts = unfiltered_posts
@@ -335,7 +343,7 @@ class TopicView
# Username filters
if @username_filters.present?
usernames = @username_filters.map{|u| u.downcase}
@filtered_posts = @filtered_posts.where('post_number = 1 or user_id in (select u.id from users u where username_lower in (?))', usernames)
@filtered_posts = @filtered_posts.where('post_number = 1 OR posts.user_id IN (SELECT u.id FROM users u WHERE username_lower IN (?))', usernames)
@contains_gaps = true
end