Fix posts not being processed by blacklist after post updates

- Blacklisting individual posts was moved into its own function
- Fixed Javascript variables being leaked into the user environment
- Fixed post qTips being orphaned by replacements by destroying them first
- Moved edit form check into post success to avoid repeating post check
This commit is contained in:
BrokenEagle
2020-03-06 21:56:04 +00:00
parent 1a2c082b86
commit d84150b232
2 changed files with 28 additions and 22 deletions

View File

@@ -118,24 +118,28 @@ Blacklist.apply = function() {
var count = 0
$.each(this.posts(), function(i, post) {
var post_count = 0;
$.each(Blacklist.entries, function(j, entry) {
if (Blacklist.post_match(post, entry)) {
entry.hits += 1;
count += 1;
post_count += 1;
}
});
if (post_count > 0) {
Blacklist.post_hide(post);
} else {
Blacklist.post_unhide(post);
}
count += Blacklist.apply_post(post);
});
return count;
}
Blacklist.apply_post = function(post) {
var post_count = 0;
$.each(Blacklist.entries, function(j, entry) {
if (Blacklist.post_match(post, entry)) {
entry.hits += 1;
post_count += 1;
}
});
if (post_count > 0) {
Blacklist.post_hide(post);
} else {
Blacklist.post_unhide(post);
}
return post_count;
};
Blacklist.posts = function() {
return $(".post-preview, #image-container, #c-comments .post, .mod-queue-preview.post-preview");
}

View File

@@ -1,14 +1,16 @@
var post_id = <%= @post.id %>;
var $post = $(`#post_${post_id}`);
<% if @post.valid? %>
$post.replaceWith("<%= j PostPresenter.preview(@post, show_deleted: true) %>");
var $post = $("#post_<%= @post.id %>");
<% if !CurrentUser.disable_post_tooltips %>
$post.find("img").qtip("destroy", true);
<% end %>
var $new_post = $("<%= j PostPresenter.preview(@post, show_deleted: true) %>");
Danbooru.Blacklist.apply_post($new_post.get(0));
$("#post_<%= @post.id %>").replaceWith($new_post);
<% if params[:mode] == "quick-edit" %>
Danbooru.PostModeMenu.close_edit_form();
<% end %>
<% else %>
Danbooru.error(`Post #${post_id}: <%= j @post.errors.full_messages.join("; ") %>`);
<% end %>
<% if @post.valid? && params[:mode] == "quick-edit" %>
Danbooru.PostModeMenu.close_edit_form();
Danbooru.error(`Post #<%= @post.id %>: <%= j @post.errors.full_messages.join("; ") %>`);
<% end %>
$(document).trigger("danbooru:post-preview-updated", <%= raw @post.to_json %>);