about summary refs log tree commit diff
path: root/app/helpers
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-08-18 15:07:15 -0500
committermultiple creatures <dev@multiple-creature.party>2019-08-18 15:14:09 -0500
commitcaec7b5ca7061235dd46bcfa08020baff01e3fd6 (patch)
tree88c4e899bd405e41c9143e3bb7c2dd82e563a163 /app/helpers
parent32e37245faaa2a29e6c748c5f4401226fb7662c4 (diff)
fix custom filter logic
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/filter_helper.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/app/helpers/filter_helper.rb b/app/helpers/filter_helper.rb
index b2b78bc44..079075a97 100644
--- a/app/helpers/filter_helper.rb
+++ b/app/helpers/filter_helper.rb
@@ -6,8 +6,11 @@ module FilterHelper
       return !(redis.hexists("custom_cw:#{receiver_id}", status.id) || redis.hexists("custom_cw:#{receiver_id}", "c#{status.conversation_id}"))
     end
 
-    filters = cached_filters(receiver_id)
-    filters.select! { |filter| filter.context.include?(context.to_s) && !filter.expired? }
+    filters = cached_filters(receiver_id).select { |filter| !filter.expired? }
+
+    unless context.nil?
+      filters.select! { |filter| filter.context.include?(context.to_s) && !filter.expired? }
+    end
 
     if status.media_attachments.any?
       filters.delete_if { |filter| filter.exclude_media }
@@ -33,9 +36,9 @@ module FilterHelper
       end
 
       matched = false
-      matched = true unless regex.match(status_text).nil?
-      matched = true unless spoiler_text.blank? || regex.match(spoiler_text).nil?
-      matched = true unless tags.empty? || regex.match(tags).nil?
+      matched ||= regex.match(status_text).present? if filter.status_text
+      matched ||= regex.match(spoiler_text).present? if filter.spoiler && spoiler_text.present?
+      matched ||= regex.match(tags).present? if filter.tags && tags.present?
 
       if matched
         filter_thread(receiver_id, status.conversation_id) if filter.thread && filter.custom_cw.blank?