diff --git a/app/javascript/src/styles/specific/comments.scss b/app/javascript/src/styles/specific/comments.scss index c39219295..680ac11b0 100644 --- a/app/javascript/src/styles/specific/comments.scss +++ b/app/javascript/src/styles/specific/comments.scss @@ -15,6 +15,26 @@ div.comments-for-post { background: $menu_color; } + &[data-is-voted="true"] { + .comment-vote-up-link, .comment-vote-down-link { + display: none; + } + } + + &[data-is-voted="false"] { + .comment-unvote-link { + display: none; + } + } + + &[data-below-threshold="true"][data-is-sticky="false"] { + opacity: 0.3; + + &:hover { + opacity: 1.0; + } + } + div.author { width: 12em; float: left; @@ -38,14 +58,6 @@ div.comments-for-post { } } } - - article.comment.below-threshold:not([data-is-sticky="true"]) { - opacity: 0.3; - } - - article.comment.below-threshold:hover { - opacity: 1.0; - } } } diff --git a/app/models/comment.rb b/app/models/comment.rb index 75eac8b4f..0f30aed63 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -167,14 +167,14 @@ class Comment < ApplicationRecord end end - def below_threshold?(user = CurrentUser.user) - score < user.comment_threshold - end - def editable_by?(user) creator_id == user.id || user.is_moderator? end + def voted_by?(user) + user.id.in?(votes.map(&:user_id)) + end + def hidden_attributes super + [:body_index] end diff --git a/app/views/comment_votes/create.js.erb b/app/views/comment_votes/create.js.erb index 966e785c4..b8f2b29bb 100644 --- a/app/views/comment_votes/create.js.erb +++ b/app/views/comment_votes/create.js.erb @@ -1,7 +1,2 @@ -<% if @comment_vote.is_negative? %> - $(".comment[data-comment-id=<%= @comment.id %>]").remove(); -<% end %> - -$("#comment-vote-up-link-for-<%= @comment.id %>").hide(); -$("#comment-vote-down-link-for-<%= @comment.id %>").hide(); -$("#comment-unvote-link-for-<%= @comment.id %>").show(); +Danbooru.Utility.notice("Vote saved"); +$(".comment[data-id=<%= @comment.id %>]").attr("data-is-voted", "true"); diff --git a/app/views/comment_votes/destroy.js.erb b/app/views/comment_votes/destroy.js.erb index a1f4739a7..bc00c5721 100644 --- a/app/views/comment_votes/destroy.js.erb +++ b/app/views/comment_votes/destroy.js.erb @@ -1,3 +1,2 @@ -$("#comment-vote-up-link-for-<%= @comment.id %>").show(); -$("#comment-vote-down-link-for-<%= @comment.id %>").show(); -$("#comment-unvote-link-for-<%= @comment.id %>").hide(); +Danbooru.Utility.notice("Removed vote"); +$(".comment[data-id=<%= @comment.id %>]").attr("data-is-voted", "false"); diff --git a/app/views/comments/destroy.js.erb b/app/views/comments/destroy.js.erb index 679b8ccc2..3b04228d3 100644 --- a/app/views/comments/destroy.js.erb +++ b/app/views/comments/destroy.js.erb @@ -1 +1 @@ -$(".comment[data-comment-id=<%= @comment.id %>] div.author h1").append(" (deleted)"); +$(".comment[data-id=<%= @comment.id %>] div.author h1").append(" (deleted)"); diff --git a/app/views/comments/partials/show/_comment.html.erb b/app/views/comments/partials/show/_comment.html.erb index 6eb97c8a8..a2b533025 100644 --- a/app/views/comments/partials/show/_comment.html.erb +++ b/app/views/comments/partials/show/_comment.html.erb @@ -1,6 +1,16 @@ <% if CurrentUser.is_moderator? || (params[:search] && params[:search][:is_deleted] =~ /t/) || !comment.is_deleted? %> -
" data-post-id="<%= comment.post_id %>" data-comment-id="<%= comment.id %>" data-score="<%= comment.score %>" data-creator="<%= comment.creator.name %>" data-is-sticky="<%= comment.is_sticky %>"> +

<%= link_to_user comment.creator %> @@ -31,9 +41,15 @@ <% end %>
  • <%= link_to "Edit", edit_comment_path(comment.id), :id => "edit_comment_link_#{comment.id}", :class => "edit_comment_link" %>
  • <% end %> - - - + + + <% if CurrentUser.is_moderator? %>
  • |