diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js index 15c6b0b02..4e5e71486 100644 --- a/app/assets/javascripts/comments.js +++ b/app/assets/javascripts/comments.js @@ -5,6 +5,7 @@ $("div.dtext-preview").hide(); this.initialize_response_link(); this.initialize_preview_button(); + this.hide_threshold_comments(); } Danbooru.Comment.initialize_response_link = function() { @@ -31,6 +32,37 @@ }); }); } + + Danbooru.Comment.highlight_threshold_comments = function(post_id) { + var threshold = parseInt(Danbooru.meta("user-comment-threshold")); + var articles = $("article.comment[data-post-id=" + post_id + "]"); + console.log("articles=%o", articles); + articles.each(function(i, v) { + var $comment = $(v); + console.log("testing %o", $comment); + if (parseInt($comment.data("score")) < threshold) { + $comment.addClass("below-threshold"); + } + }) + } + + Danbooru.Comment.hide_threshold_comments = function(post_id) { + var threshold = parseInt(Danbooru.meta("user-comment-threshold")); + var articles = null; + + if (post_id) { + articles = $("article.comment[data-post-id=" + post_id + "]"); + } else { + articles = $("article.comment"); + } + + articles.each(function(i, v) { + var $comment = $(v); + if (parseInt($comment.data("score")) < threshold) { + $comment.hide(); + } + }); + } })(); $(document).ready(function() { diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 4fb0a0c93..d1422eb35 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -539,7 +539,7 @@ div#c-pool-orders { div.comments-for-post { div.list-of-comments { - article { + article.comment { margin-bottom: 2em; div.author { @@ -558,6 +558,14 @@ div.comments-for-post { float: left; } } + + article.comment.below-threshold { + opacity: 0.2; + } + + article.comment.below-threshold:hover { + opacity: 1.0; + } } div.comment-preview { diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index fad8a6fdc..20100c6cb 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -40,7 +40,7 @@ private def index_for_post @post = Post.find(params[:post_id]) @comments = @post.comments - @comments = @comments.visible unless params[:include_hidden] + @comments = @comments.visible(CurrentUser.user) unless params[:include_below_threshold] render :action => "index_for_post" end diff --git a/app/views/comments/index_for_post.js.erb b/app/views/comments/index_for_post.js.erb index 720309a40..264fb7bc7 100644 --- a/app/views/comments/index_for_post.js.erb +++ b/app/views/comments/index_for_post.js.erb @@ -1 +1,11 @@ -$("div.comments-for-post[data-post-id=<%= @post.id %>] div.notices").hide(); +$("#hidden-comments-notice-for-<%= @post.id %>").hide(); + +$("div.comments-for-post[data-post-id=<%= @post.id %>] div.list-of-comments").html("<%= j(render(:partial => 'comments/partials/show/comment', :collection => @comments))%>"); + +<% if params[:include_below_threshold] %> + $("#threshold-comments-notice-for-<%= @post.id %>").hide(); + Danbooru.Comment.highlight_threshold_comments(<%= @post.id %>); +<% else %> + Danbooru.Comment.hide_threshold_comments(<%= @post.id %>); +<% end %> + diff --git a/app/views/comments/partials/index/_header.html.erb b/app/views/comments/partials/index/_header.html.erb index 9d79719ae..edfcab2e4 100644 --- a/app/views/comments/partials/index/_header.html.erb +++ b/app/views/comments/partials/index/_header.html.erb @@ -33,12 +33,12 @@
<% if post.comments.count > 6 %> - <%= link_to "#{pluralize(post.comments.size, 'comment')} hidden", comments_path(:post_id => post.id), :remote => true %>. + <%= link_to "#{pluralize(post.comments.size, 'comment')} hidden", comments_path(:post_id => post.id), :remote => true %> <% end %> <% if post.comments.hidden(CurrentUser.user).count > 0 %> - <%= link_to "#{pluralize(post.comments.hidden(CurrentUser.user).count, 'comment')} below threshold", comments_path(:post_id => post.id, :include_hidden => true), :remote => true %>. + <%= link_to "#{pluralize(post.comments.hidden(CurrentUser.user).count, 'comment')} below threshold", comments_path(:post_id => post.id, :include_below_threshold => true), :remote => true %> <% end %>
diff --git a/app/views/comments/partials/show/_comment.html.erb b/app/views/comments/partials/show/_comment.html.erb index b91bac47f..ddd8a7d0a 100644 --- a/app/views/comments/partials/show/_comment.html.erb +++ b/app/views/comments/partials/show/_comment.html.erb @@ -1,4 +1,4 @@ -
+

<%= link_to comment.creator_name, user_path(comment.creator_id) %>

diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb index edc54c776..aba793616 100644 --- a/app/views/layouts/default.html.erb +++ b/app/views/layouts/default.html.erb @@ -7,6 +7,7 @@ <%= csrf_meta_tag %> + <% unless CurrentUser.user.blacklisted_tags.blank? %> <% end %> diff --git a/db/seeds.rb b/db/seeds.rb index 74146914e..b8dd8c96d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -45,7 +45,9 @@ end if Comment.count == 0 puts "Creating comments" Post.all.each do |post| - Comment.create(:post_id => post.id, :body => rand(1_000_000).to_s) + 20.times do + Comment.create(:post_id => post.id, :body => rand(1_000_000).to_s) + end end else puts "Skipping comments"