diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index cc2fe2fdc..89baa8fe1 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -268,6 +268,7 @@ class StoriesController < ApplicationController end @comments_to_show_count = @article.cached_tag_list_array.include?("discuss") ? 50 : 30 + @comments_to_show_count = 15 unless user_signed_in? set_article_json_ld assign_co_authors @comment = Comment.new(body_markdown: @article&.comment_template) diff --git a/app/decorators/article_decorator.rb b/app/decorators/article_decorator.rb index b287682f7..104fbcf5c 100644 --- a/app/decorators/article_decorator.rb +++ b/app/decorators/article_decorator.rb @@ -33,10 +33,6 @@ class ArticleDecorator < ApplicationDecorator end end - def comments_to_show_count - cached_tag_list_array.include?("discuss") ? 75 : 25 - end - def cached_tag_list_array (cached_tag_list || "").split(", ") end diff --git a/app/decorators/podcast_episode_decorator.rb b/app/decorators/podcast_episode_decorator.rb index c70763a67..b3bf1b732 100644 --- a/app/decorators/podcast_episode_decorator.rb +++ b/app/decorators/podcast_episode_decorator.rb @@ -1,8 +1,4 @@ class PodcastEpisodeDecorator < ApplicationDecorator - def comments_to_show_count - cached_tag_list_array.include?("discuss") ? 75 : 25 - end - # this method exists because podcast episodes are "commentables" # and in some parts of the code we assume they have this method, # but podcast episodes don't have a cached_tag_list like articles do diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 9b802c13b..c1f6735c3 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -2,6 +2,34 @@ module CommentsHelper MAX_COMMENTS_TO_RENDER = 250 MIN_COMMENTS_TO_RENDER = 8 + def any_negative_comments?(commentable) + commentable.comments.where("score < 0").any? + end + + def any_hidden_negative_comments?(commentable) + !user_signed_in? && any_negative_comments?(commentable) + end + + def all_comments_visible?(commentable) + !(commentable.any_comments_hidden || any_hidden_negative_comments?(commentable)) + end + + def article_comment_tree(article, count, order) + @article_comment_tree ||= begin + collection = Comment.tree_for(article, count, order) + collection.reject! { |comment| comment.score.negative? } unless user_signed_in? + collection + end + end + + def podcast_comment_tree(episode) + @podcast_comment_tree ||= begin + collection = Comment.tree_for(episode, 12) + collection.reject! { |comment| comment.score.negative? } unless user_signed_in? + collection + end + end + def comment_class(comment, is_view_root: false) if comment.root? || is_view_root "root" diff --git a/app/views/articles/_comments_actions.html.erb b/app/views/articles/_comments_actions.html.erb index 5e8232494..399c33309 100644 --- a/app/views/articles/_comments_actions.html.erb +++ b/app/views/articles/_comments_actions.html.erb @@ -7,9 +7,10 @@ <% end %> - <% if @article.any_comments_hidden %> + <% unless all_comments_visible?(@article) %>
- <%= t("views.comments.hidden.text_html", info: link_to(t("views.comments.hidden.info"), "/faq")) %> + <%= t("views.comments.visible_signed_in.text_html", sign_in: link_to(t("views.comments.visible_signed_in.sign_in"), "/enter")) if any_hidden_negative_comments?(@article) %> + <%= t("views.comments.hidden.text_html", info: link_to(t("views.comments.hidden.info"), "/faq")) if @article.any_comments_hidden %>
<% end %> diff --git a/app/views/articles/_full_comment_area.html.erb b/app/views/articles/_full_comment_area.html.erb index a87976789..eff71ad69 100644 --- a/app/views/articles/_full_comment_area.html.erb +++ b/app/views/articles/_full_comment_area.html.erb @@ -55,7 +55,10 @@