about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2020-01-10 14:19:04 -0600
committermultiple creatures <dev@multiple-creature.party>2020-01-10 14:19:04 -0600
commit13b4d7953adfa8455f800a56124c7d6ecafa41ca (patch)
tree76fa5d86a2e646c09b08637625cc31aaa2f694b0 /app
parente13202c114eeb7584e776a073a41d9e57ae31e02 (diff)
add ability to toggle individual filters without deleting them
Diffstat (limited to 'app')
-rw-r--r--app/controllers/api/v1/filters_controller.rb2
-rw-r--r--app/controllers/filters_controller.rb2
-rw-r--r--app/models/custom_filter.rb3
-rw-r--r--app/models/status.rb6
-rw-r--r--app/views/filters/_fields.html.haml3
-rw-r--r--app/views/filters/index.html.haml2
6 files changed, 13 insertions, 5 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