about summary refs log tree commit diff
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-11-17 21:29:07 -0600
committermultiple creatures <dev@multiple-creature.party>2019-11-18 02:19:09 -0600
commitafe4b6b6adfe5f40c6c327b97a941a25c2e93798 (patch)
treeadc70100a6cf69473395b92e4336539aad6e18cc
parentb1049bc149d5a9891d50a6e7546f91c278a5b086 (diff)
Users' filters are applied in the `Status` model. They can also now use regular expressions.
-rw-r--r--app/models/status.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/app/models/status.rb b/app/models/status.rb
index ac40b2acb..18604488e 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -118,6 +118,10 @@ class Status < ApplicationRecord
   scope :reply_not_excluded_by_account, ->(account) { where('statuses.in_reply_to_account_id IS NULL OR statuses.in_reply_to_account_id NOT IN (?)', account.excluded_from_timeline_account_ids) }
   scope :mention_not_excluded_by_account, ->(account) { left_outer_joins(:mentions).where('mentions.account_id IS NULL OR mentions.account_id NOT IN (?)', account.excluded_from_timeline_account_ids) }
   scope :not_domain_blocked_by_account, ->(account) { account.excluded_from_timeline_domains.blank? ? left_outer_joins(:account) : left_outer_joins(:account).where('accounts.domain IS NULL OR accounts.domain NOT IN (?)', account.excluded_from_timeline_domains) }
+
+  scope :not_string_filtered_by_account, ->(account) { where("statuses.normalized_text !~ ANY(ARRAY(#{account.custom_filters.select('unaccent(lower(phrase))').to_sql}))") }
+  scope :not_missing_media_desc, -> { left_outer_joins(:media_attachments).where('media_attachments.id IS NULL OR media_attachments.description IS NOT NULL') }
+
   scope :tagged_with_all, ->(tags) {
     Array(tags).map(&:id).map(&:to_i).reduce(self) do |result, id|
       result.joins("INNER JOIN statuses_tags t#{id} ON t#{id}.status_id = statuses.id AND t#{id}.tag_id = #{id}")
@@ -550,6 +554,8 @@ class Status < ApplicationRecord
       query = query.in_chosen_languages(account) if account.chosen_languages.present?
       query = query.reply_not_excluded_by_account(account) unless tag_timeline
       query = query.mention_not_excluded_by_account(account)
+      query = query.not_string_filtered_by_account(account)
+      query = query.not_missing_media_desc if account.filter_undescribed?
       query.merge(account_silencing_filter(account))
     end