From 276f23ba8d1302b3b335cadb102a0062874355cf Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 2 Jun 2020 18:19:16 -0500 Subject: [PATCH] config: refactor `remove_tag_after_replacement?` config option. --- app/models/post_replacement.rb | 7 ++++++- config/danbooru_default_config.rb | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/post_replacement.rb b/app/models/post_replacement.rb index 7eb9bcc69..40cbaed2d 100644 --- a/app/models/post_replacement.rb +++ b/app/models/post_replacement.rb @@ -29,7 +29,12 @@ class PostReplacement < ApplicationRecord end def suggested_tags_for_removal - tags = post.tag_array.select { |tag| Danbooru.config.remove_tag_after_replacement?(tag) } + tags = post.tag_array.select do |tag| + Danbooru.config.post_replacement_tag_removals.any? do |pattern| + tag.match?(/\A#{pattern}\z/i) + end + end + tags = tags.map { |tag| "-#{tag}" } tags.join(" ") end diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index 55e145a19..73b5df007 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -321,9 +321,10 @@ module Danbooru nil end - # Should return true if the given tag should be suggested for removal in the post replacement dialog box. - def remove_tag_after_replacement?(tag) - tag =~ /\A(?:replaceme|.*_sample|resized|upscaled|downscaled|md5_mismatch|jpeg_artifacts|corrupted_image|source_request|non-web_source)\z/i + # A list of tags that should be removed when a post is replaced. Regexes allowed. + def post_replacement_tag_removals + %w[replaceme .*_sample resized upscaled downscaled md5_mismatch + jpeg_artifacts corrupted_image source_request non-web_source] end # Posts with these tags will be highlighted in the modqueue.