diff options
author | multiple creatures <dev@multiple-creature.party> | 2019-12-21 13:22:18 -0600 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2019-12-21 13:22:18 -0600 |
commit | 8312a6e51017498c417070cbcbf115da184b786d (patch) | |
tree | 21adc50927a531cc204bc6abd6165abdf930d3a6 /app | |
parent | b8f7ccf22729b77fbb5a44ecda01de5329d07adc (diff) |
add option to use phrase filters as an allow list
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/settings/preferences_controller.rb | 3 | ||||
-rw-r--r-- | app/lib/status_filter.rb | 9 | ||||
-rw-r--r-- | app/models/status.rb | 8 | ||||
-rw-r--r-- | app/models/user.rb | 1 | ||||
-rw-r--r-- | app/views/settings/preferences/show.html.haml | 1 |
5 files changed, 18 insertions, 4 deletions
diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index 66e9033d3..4ac654590 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Settings::PreferencesController < Settings::BaseController + include Redisable + layout 'admin' before_action :authenticate_user! @@ -29,6 +31,7 @@ class Settings::PreferencesController < Settings::BaseController :locale, :hide_boosts, :only_known, + :invert_filters, chosen_languages: [] ) end diff --git a/app/lib/status_filter.rb b/app/lib/status_filter.rb index 81faf129f..fb675cbbd 100644 --- a/app/lib/status_filter.rb +++ b/app/lib/status_filter.rb @@ -15,7 +15,7 @@ class StatusFilter def filtered? return true if status.nil? || account.nil? return false if !account.nil? && account.id == status.account_id - return true if redis.sismember("filtered_statuses:#{account.id}", status.id) + return !account.user.invert_filters if redis.sismember("filtered_statuses:#{account.id}", status.id) if blocked_by_policy? || (account_present? && filtered_status?) || silenced_account? redis.sadd("filtered_statuses:#{account.id}", status.id) return true @@ -40,7 +40,7 @@ class StatusFilter return true if account.user_hides_replies_of_blocker? && reply_to_blocker? # filtered by user? - return true if phrase_filtered?(status, account.id) + return true if !account.user.invert_filters && phrase_filtered?(status, account.id) # kajiht has no filters if status has no mentions return false if status&.mentions.blank? @@ -74,7 +74,10 @@ class StatusFilter return true if !@preloaded_relations[:muting] && account.user_hides_mentions_of_muted? && account.muting?(mentioned_account_ids) return true if !@preloaded_relations[:blocking] && account.user_hides_mentions_of_blocked? && account.blocking?(mentioned_account_ids) return false unless status.reply? && status.private_visibility? && account.user_hides_mentions_outside_scope? - !@preloaded_relations[:following] && (mentioned_account_ids - account.following_ids).any? + return true if !@preloaded_relations[:following] && (mentioned_account_ids - account.following_ids).any? + + # filtered by user? + account.user.invert_filters && !phrase_filtered?(status, account.id) end def reply_to_blocked? diff --git a/app/models/status.rb b/app/models/status.rb index 8a1680ccf..a47f846a5 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -580,7 +580,13 @@ 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.regex_not_filtered_by_account(account.id) if account.custom_filters.present? + unless account.custom_filters.nil? + if account.user.invert_filters + query = query.regex_filtered_by_account(account.id) + else + query = query.regex_not_filtered_by_account(account.id) + end + end query = query.not_missing_media_desc if account.filter_undescribed? query.merge(account_silencing_filter(account)) end diff --git a/app/models/user.rb b/app/models/user.rb index 59067cb36..f6e1a369d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -41,6 +41,7 @@ # vars :jsonb not null # hide_boosts :boolean # only_known :boolean +# invert_filters :boolean default(FALSE), not null # class User < ApplicationRecord diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml index 81bfc7345..8f4563fde 100644 --- a/app/views/settings/preferences/show.html.haml +++ b/app/views/settings/preferences/show.html.haml @@ -46,6 +46,7 @@ %hr#settings_other/ .fields-group + = f.input :invert_filters, as: :boolean, wrapper: :with_label = f.input :setting_rawr_federated, as: :boolean, wrapper: :with_label = f.input :hide_boosts, as: :boolean, wrapper: :with_label = f.input :only_known, as: :boolean, wrapper: :with_label |