diff options
-rw-r--r-- | app/controllers/api/v1/filters_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/filters_controller.rb | 2 | ||||
-rw-r--r-- | app/models/custom_filter.rb | 3 | ||||
-rw-r--r-- | app/models/status.rb | 6 | ||||
-rw-r--r-- | app/views/filters/_fields.html.haml | 3 | ||||
-rw-r--r-- | app/views/filters/index.html.haml | 2 | ||||
-rw-r--r-- | config/locales/simple_form.en.yml | 2 | ||||
-rw-r--r-- | db/migrate/20200110195612_toggleable_filters.rb | 7 | ||||
-rw-r--r-- | db/structure.sql | 17 | ||||
-rw-r--r-- | streaming/index.js | 2 |
10 files changed, 37 insertions, 9 deletions
diff --git a/app/controllers/api/v1/filters_controller.rb b/app/controllers/api/v1/filters_controller.rb index de2c90dba..514f7c8fa 100644 --- a/app/controllers/api/v1/filters_controller.rb +++ b/app/controllers/api/v1/filters_controller.rb @@ -43,6 +43,6 @@ class Api::V1::FiltersController < Api::BaseController end def resource_params - params.permit(:phrase, :expires_in) + params.permit(:phrase, :expires_in, :is_enabled) end end diff --git a/app/controllers/filters_controller.rb b/app/controllers/filters_controller.rb index 9fa653b11..f5cc00d2f 100644 --- a/app/controllers/filters_controller.rb +++ b/app/controllers/filters_controller.rb @@ -58,7 +58,7 @@ class FiltersController < ApplicationController end def resource_params - params.require(:custom_filter).permit(:phrase, :expires_in) + params.require(:custom_filter).permit(:phrase, :expires_in, :is_enabled) end def set_body_classes diff --git a/app/models/custom_filter.rb b/app/models/custom_filter.rb index e5e0d1554..f60c42121 100644 --- a/app/models/custom_filter.rb +++ b/app/models/custom_filter.rb @@ -9,12 +9,15 @@ # phrase :text default(""), not null # created_at :datetime not null # updated_at :datetime not null +# is_enabled :boolean default(TRUE), not null # class CustomFilter < ApplicationRecord include Expireable include Redisable + scope :enabled, -> { where(is_enabled: true) } + belongs_to :account validates :phrase, presence: true diff --git a/app/models/status.rb b/app/models/status.rb index 515553708..5a1d38932 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -119,8 +119,8 @@ class Status < ApplicationRecord scope :search, ->(needle) { where("tsv @@ websearch_to_tsquery('fedi', ?)", needle) } scope :search_not, ->(needle) { where.not("tsv @@ websearch_to_tsquery('fedi', ?)", needle) } - scope :search_filtered_by_account, ->(account_id) { where('tsv @@ (SELECT tsquery_union(websearch_to_tsquery(phrase)) FROM custom_filters WHERE account_id = ?)', account_id) } - scope :search_not_filtered_by_account, ->(account_id) { where.not('tsv @@ (SELECT tsquery_union(websearch_to_tsquery(phrase)) FROM custom_filters WHERE account_id = ?)', account_id) } + scope :search_filtered_by_account, ->(account_id) { where('tsv @@ (SELECT tsquery_union(websearch_to_tsquery(phrase)) FROM custom_filters WHERE account_id = ? AND is_enabled)', account_id) } + scope :search_not_filtered_by_account, ->(account_id) { where.not('tsv @@ (SELECT tsquery_union(websearch_to_tsquery(phrase)) FROM custom_filters WHERE account_id = ? AND is_enabled)', account_id) } scope :not_missing_media_desc, -> { left_outer_joins(:media_attachments).select('statuses.*').where('media_attachments.id IS NULL OR media_attachments.description IS NOT NULL') } @@ -578,7 +578,7 @@ 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) - unless account.custom_filters.empty? + unless account.custom_filters.enabled.empty? if account.user.invert_filters query = query.search_filtered_by_account(account.id) else diff --git a/app/views/filters/_fields.html.haml b/app/views/filters/_fields.html.haml index 3df611596..1314e8e02 100644 --- a/app/views/filters/_fields.html.haml +++ b/app/views/filters/_fields.html.haml @@ -1,7 +1,10 @@ .fields-row + .fields-row__column.fields-row__column-6.fields-group = f.input :phrase, as: :string, wrapper: :with_label %p.hint{ style: 'margin-bottom: 25px' }= t('simple_form.hints.defaults.phrase_html') + = f.input :is_enabled, as: :boolean, wrapper: :with_label + .fields-row__column.fields-row__column-6.fields-group = f.input :expires_in, wrapper: :with_label, collection: [30.minutes, 1.hour, 6.hours, 12.hours, 1.day, 1.week].map(&:to_i), label_method: lambda { |i| I18n.t("invites.expires_in.#{i}") }, prompt: I18n.t('invites.expires_in_prompt') diff --git a/app/views/filters/index.html.haml b/app/views/filters/index.html.haml index 228474f01..44fed886d 100644 --- a/app/views/filters/index.html.haml +++ b/app/views/filters/index.html.haml @@ -6,11 +6,13 @@ %thead %tr %th= t('simple_form.labels.defaults.phrase') + %th= t('simple_form.labels.defaults.is_enabled') %th %tbody - @filters.each do |filter| %tr %td= filter.phrase + %td= (filter.is_enabled ? "\u2705" : "\u274c") %td = table_link_to 'pencil', t('filters.edit.title'), edit_filter_path(filter) = table_link_to 'times', t('filters.index.delete'), filter_path(filter), method: :delete diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index eefa3530d..aa32a3200 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -193,7 +193,7 @@ en: desc: Filter roars with matching media descriptions no_desc: Filter roars WITHOUT media descriptions override_cw: Override existing content warning - + is_enabled: Enabled filter_undescribed: Hide roars without media descriptions boost_interval: 1: 1 minute diff --git a/db/migrate/20200110195612_toggleable_filters.rb b/db/migrate/20200110195612_toggleable_filters.rb new file mode 100644 index 000000000..4bc521bf3 --- /dev/null +++ b/db/migrate/20200110195612_toggleable_filters.rb @@ -0,0 +1,7 @@ +class ToggleableFilters < ActiveRecord::Migration[5.2] + def change + safety_assured { + add_column :custom_filters, :is_enabled, :boolean, null: false, default: true + } + end +end diff --git a/db/structure.sql b/db/structure.sql index 3ac813d4c..de17e54f8 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -114,6 +114,17 @@ $$; -- +-- Name: tsquery_union(tsquery); Type: AGGREGATE; Schema: public; Owner: - +-- + +CREATE AGGREGATE public.tsquery_union(tsquery) ( + SFUNC = tsquery_or, + STYPE = tsquery, + PARALLEL = safe +); + + +-- -- Name: fedi; Type: TEXT SEARCH CONFIGURATION; Schema: public; Owner: - -- @@ -862,7 +873,8 @@ CREATE TABLE public.custom_filters ( expires_at timestamp without time zone, phrase text DEFAULT ''::text NOT NULL, created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + updated_at timestamp without time zone NOT NULL, + is_enabled boolean DEFAULT true NOT NULL ); @@ -5377,6 +5389,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20191221195147'), ('20200108051211'), ('20200109191740'), -('20200110072034'); +('20200110072034'), +('20200110195612'); diff --git a/streaming/index.js b/streaming/index.js index fe61c5c2e..f429bbcc1 100644 --- a/streaming/index.js +++ b/streaming/index.js @@ -424,7 +424,7 @@ const startWorker = (workerId) => { } const queries = [ - client.query(`SELECT 1 FROM blocks WHERE (account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 3)})) OR (account_id = $2 AND target_account_id = $1) UNION SELECT 1 FROM mutes WHERE account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 3)}) UNION SELECT 1 FROM statuses WHERE id = $3 ${req.invertFilters ? 'AND NOT' : 'AND'} tsv @@ (SELECT tsquery_union(websearch_to_tsquery(phrase)) FROM custom_filters WHERE account_id = $1) UNION SELECT 1 FROM media_attachments WHERE (1 = (SELECT 1 FROM accounts WHERE id = $1 AND filter_undescribed)) AND status_id = $3 AND description IS NULL LIMIT 1`, [req.accountId, unpackedPayload.account.id, unpackedPayload.id].concat(targetAccountIds)), + client.query(`SELECT 1 FROM blocks WHERE (account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 3)})) OR (account_id = $2 AND target_account_id = $1) UNION SELECT 1 FROM mutes WHERE account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 3)}) UNION SELECT 1 FROM statuses WHERE id = $3 ${req.invertFilters ? 'AND NOT' : 'AND'} tsv @@ (SELECT tsquery_union(websearch_to_tsquery(phrase)) FROM custom_filters WHERE account_id = $1 AND is_enabled) UNION SELECT 1 FROM media_attachments WHERE (1 = (SELECT 1 FROM accounts WHERE id = $1 AND filter_undescribed)) AND status_id = $3 AND description IS NULL LIMIT 1`, [req.accountId, unpackedPayload.account.id, unpackedPayload.id].concat(targetAccountIds)), ]; if (accountDomain) { |