comments.js: fix thresholded comments.
* Restore behavior of thresholded comments being greyed out (lost in 6fa0ae2cf).
* Set the `below-threshold` class for thresholded comments in the html instead of in javascript.
* Remove `include_below_threshold` param; it was always true when clicking "Show all comments".
This commit is contained in:
@@ -70,7 +70,6 @@ private
|
|||||||
def index_for_post
|
def index_for_post
|
||||||
@post = Post.find(params[:post_id])
|
@post = Post.find(params[:post_id])
|
||||||
@comments = @post.comments
|
@comments = @post.comments
|
||||||
@comments = @comments.visible(CurrentUser.user) unless params[:include_below_threshold]
|
|
||||||
render :action => "index_for_post"
|
render :action => "index_for_post"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -11,16 +11,8 @@ Comment.initialize_all = function() {
|
|||||||
this.initialize_expand_links();
|
this.initialize_expand_links();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($("#c-posts").length && $("#a-show").length) {
|
$(window).on("danbooru:index_for_post", (_event, post_id, current_comment_section) => {
|
||||||
Comment.highlight_threshold_comments(Utility.meta("post-id"));
|
$("#threshold-comments-notice-for-" + post_id).hide();
|
||||||
}
|
|
||||||
|
|
||||||
$(window).on("danbooru:index_for_post", (_event, post_id, current_comment_section, include_below_threshold) => {
|
|
||||||
if (include_below_threshold) {
|
|
||||||
$("#threshold-comments-notice-for-" + post_id).hide();
|
|
||||||
} else {
|
|
||||||
Comment.highlight_threshold_comments(post_id);
|
|
||||||
}
|
|
||||||
Dtext.initialize_expandables(current_comment_section);
|
Dtext.initialize_expandables(current_comment_section);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -67,17 +59,6 @@ Comment.show_edit_form = function(e) {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
Comment.highlight_threshold_comments = function(post_id) {
|
|
||||||
var threshold = parseInt(Utility.meta("user-comment-threshold"));
|
|
||||||
var articles = $("article.comment[data-post-id=" + post_id + "]");
|
|
||||||
articles.each(function(i, v) {
|
|
||||||
var $comment = $(v);
|
|
||||||
if (parseInt($comment.data("score")) < threshold) {
|
|
||||||
$comment.addClass("below-threshold");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Comment.hide_threshold_comments = function(post_id) {
|
Comment.hide_threshold_comments = function(post_id) {
|
||||||
var threshold = parseInt(Utility.meta("user-comment-threshold"));
|
var threshold = parseInt(Utility.meta("user-comment-threshold"));
|
||||||
var articles = $("article.comment[data-post-id=" + post_id + "]");
|
var articles = $("article.comment[data-post-id=" + post_id + "]");
|
||||||
|
|||||||
@@ -189,6 +189,10 @@ class Comment < ApplicationRecord
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def below_threshold?(user = CurrentUser.user)
|
||||||
|
score < user.comment_threshold
|
||||||
|
end
|
||||||
|
|
||||||
def editable_by?(user)
|
def editable_by?(user)
|
||||||
creator_id == user.id || user.is_moderator?
|
creator_id == user.id || user.is_moderator?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ $("#hidden-comments-notice-for-<%= @post.id %>").hide();
|
|||||||
|
|
||||||
var current_comment_section = $("div.comments-for-post[data-post-id=<%= @post.id %>] div.list-of-comments");
|
var current_comment_section = $("div.comments-for-post[data-post-id=<%= @post.id %>] div.list-of-comments");
|
||||||
current_comment_section.html("<%= j(render(:partial => 'comments/partials/show/comment', :collection => @comments))%>");
|
current_comment_section.html("<%= j(render(:partial => 'comments/partials/show/comment', :collection => @comments))%>");
|
||||||
$(window).trigger("danbooru:index_for_post", [<%= @post.id %>, current_comment_section, <%= ActiveModel::Type::Boolean.new.cast(params[:include_below_threshold]) %>]);
|
$(window).trigger("danbooru:index_for_post", [<%= @post.id %>, current_comment_section]);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<div class="row notices">
|
<div class="row notices">
|
||||||
<% if post.comments.hidden(CurrentUser.user).count > 0 || (params[:controller] == "comments" && post.comments.count > 6) %>
|
<% if post.comments.hidden(CurrentUser.user).count > 0 || (params[:controller] == "comments" && post.comments.count > 6) %>
|
||||||
<span class="info" id="threshold-comments-notice-for-<%= post.id %>">
|
<span class="info" id="threshold-comments-notice-for-<%= post.id %>">
|
||||||
<%= link_to "Show all comments", comments_path(:post_id => post.id, :include_below_threshold => true), :remote => true %>
|
<%= link_to "Show all comments", comments_path(:post_id => post.id), :remote => true %>
|
||||||
</span>
|
</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<% if CurrentUser.is_moderator? || (params[:search] && params[:search][:is_deleted] =~ /t/) || !comment.is_deleted? %>
|
<% if CurrentUser.is_moderator? || (params[:search] && params[:search][:is_deleted] =~ /t/) || !comment.is_deleted? %>
|
||||||
<a name="comment-<%= comment.id %>"></a>
|
<a name="comment-<%= comment.id %>"></a>
|
||||||
<article class="comment" 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 %>">
|
<article class="comment <%= "below-threshold" if comment.below_threshold? %>" 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 %>">
|
||||||
<div class="author">
|
<div class="author">
|
||||||
<h1>
|
<h1>
|
||||||
<%= link_to_user comment.creator %>
|
<%= link_to_user comment.creator %>
|
||||||
|
|||||||
Reference in New Issue
Block a user