From 99fd0a917df4345812794b2165efb9aa591a6512 Mon Sep 17 00:00:00 2001 From: kikito Date: Tue, 1 Sep 2015 13:10:19 +0200 Subject: [PATCH] Uses @comment_flags in everything comment-related --- app/controllers/application_controller.rb | 4 ++++ app/controllers/comments_controller.rb | 2 ++ app/controllers/debates_controller.rb | 3 +++ app/helpers/flags_helper.rb | 6 +++++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0ddb59bb3..9a84e9abd 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -71,6 +71,10 @@ class ApplicationController < ActionController::Base @debate_votes = current_user ? current_user.debate_votes(debates) : {} end + def set_comment_flags(comments) + @comment_flags = current_user ? current_user.comment_flags(comments) : {} + end + def ensure_signup_complete # Ensure we don't go into an infinite loop return if action_name.in? %w(finish_signup do_finish_signup) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index e792240f8..076b33fce 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -24,11 +24,13 @@ class CommentsController < ApplicationController def flag Flag.flag(current_user, @comment) + set_comment_flags(@comment) respond_with @comment, template: 'comments/_refresh_flag_actions' end def unflag Flag.unflag(current_user, @comment) + set_comment_flags(@comment) respond_with @comment, template: 'comments/_refresh_flag_actions' end diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index 2f660c1c7..87df13d37 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -15,6 +15,9 @@ class DebatesController < ApplicationController def show set_debate_votes(@debate) @comments = @debate.root_comments.recent.page(params[:page]).for_render + # TODO limit this list to the paginated root comment's children once we have ancestry + all_visible_comments = @debate.comment_threads + set_comment_flags(all_visible_comments) end def new diff --git a/app/helpers/flags_helper.rb b/app/helpers/flags_helper.rb index 3a8bfbc75..b54c86b48 100644 --- a/app/helpers/flags_helper.rb +++ b/app/helpers/flags_helper.rb @@ -10,7 +10,11 @@ module FlagsHelper private def flagged?(flaggable) - Flag.flagged?(current_user, flaggable) + if flaggable.is_a? Comment + @comment_flags[flaggable.id] + else + Flag.flagged?(current_user, flaggable) + end end def own_flaggable?(flaggable)