add ability to toggle individual filters without deleting them
parent
e13202c114
commit
13b4d7953a
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -113,6 +113,17 @@ CREATE FUNCTION public.timestamp_id(table_name text) RETURNS bigint
|
|||
$$;
|
||||
|
||||
|
||||
--
|
||||
-- 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');
|
||||
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue