about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/api/v1/filters_controller.rb2
-rw-r--r--app/controllers/filters_controller.rb2
-rw-r--r--app/helpers/filter_helper.rb2
-rw-r--r--app/models/custom_filter.rb1
-rw-r--r--app/views/filters/_fields.html.haml1
-rw-r--r--config/locales/simple_form.en.yml1
-rw-r--r--db/migrate/20191009231327_add_desc_to_custom_filters.rb7
-rw-r--r--db/schema.rb3
8 files changed, 16 insertions, 3 deletions
diff --git a/app/controllers/api/v1/filters_controller.rb b/app/controllers/api/v1/filters_controller.rb
index 6cba4b23f..6b8b82285 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, :whole_word, :exclude_media, :media_only, :status_text, :spoiler, :tags, :custom_cw, :override_cw, context: [])
+    params.permit(:phrase, :expires_in, :whole_word, :exclude_media, :media_only, :status_text, :spoiler, :tags, :custom_cw, :override_cw, :desc, context: [])
   end
 end
diff --git a/app/controllers/filters_controller.rb b/app/controllers/filters_controller.rb
index c58da753b..c80e6853a 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, :irreversible, :whole_word, :exclude_media, :media_only, :status_text, :spoiler, :tags, :custom_cw, :override_cw, context: [])
+    params.require(:custom_filter).permit(:phrase, :expires_in, :irreversible, :whole_word, :exclude_media, :media_only, :status_text, :spoiler, :tags, :custom_cw, :override_cw, :desc, context: [])
   end
 
   def set_body_classes
diff --git a/app/helpers/filter_helper.rb b/app/helpers/filter_helper.rb
index 079075a97..3e3b4b748 100644
--- a/app/helpers/filter_helper.rb
+++ b/app/helpers/filter_helper.rb
@@ -24,6 +24,7 @@ module FilterHelper
     status_text = Formatter.instance.plaintext(status)
     spoiler_text = status.spoiler_text
     tags = status.tags.pluck(:name).join("\n")
+    descs = status.media_attachments.map { |a| a.description }.join("\n").strip
 
     filters.each do |filter|
       if filter.whole_word
@@ -39,6 +40,7 @@ module FilterHelper
       matched ||= regex.match(status_text).present? if filter.status_text
       matched ||= regex.match(spoiler_text).present? if filter.spoiler && spoiler_text.present?
       matched ||= regex.match(tags).present? if filter.tags && tags.present?
+      matched ||= regex.match(descs).present? if filter.desc && descs.present?
 
       if matched
         filter_thread(receiver_id, status.conversation_id) if filter.thread && filter.custom_cw.blank?
diff --git a/app/models/custom_filter.rb b/app/models/custom_filter.rb
index ddf6cc7ab..fb269d8f4 100644
--- a/app/models/custom_filter.rb
+++ b/app/models/custom_filter.rb
@@ -20,6 +20,7 @@
 #  status_text   :boolean          default(FALSE), not null
 #  custom_cw     :text
 #  override_cw   :boolean          default(FALSE), not null
+#  desc          :boolean          default(FALSE), not null
 #
 
 class CustomFilter < ApplicationRecord
diff --git a/app/views/filters/_fields.html.haml b/app/views/filters/_fields.html.haml
index 27561c466..6389e11b1 100644
--- a/app/views/filters/_fields.html.haml
+++ b/app/views/filters/_fields.html.haml
@@ -16,6 +16,7 @@
   = f.input :status_text, wrapper: :with_label
   = f.input :spoiler, wrapper: :with_label
   = f.input :tags, wrapper: :with_label
+  = f.input :desc, wrapper: :with_label
   = f.input :thread, wrapper: :with_label
   = f.input :media_only, wrapper: :with_label
   = f.input :exclude_media, wrapper: :with_label
diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml
index 953c97d75..9f0e5aad7 100644
--- a/config/locales/simple_form.en.yml
+++ b/config/locales/simple_form.en.yml
@@ -182,6 +182,7 @@ en:
         username_or_email: Username or Email
         whole_word: Whole word
         custom_cw: Set or prepend content warning
+        desc: Filter roars with matching media descriptions
         override_cw: Override existing content warning
       boost_interval:
         1: 1 minute
diff --git a/db/migrate/20191009231327_add_desc_to_custom_filters.rb b/db/migrate/20191009231327_add_desc_to_custom_filters.rb
new file mode 100644
index 000000000..f53f6849f
--- /dev/null
+++ b/db/migrate/20191009231327_add_desc_to_custom_filters.rb
@@ -0,0 +1,7 @@
+class AddDescToCustomFilters < ActiveRecord::Migration[5.2]
+  def change
+    safety_assured {
+      add_column :custom_filters, :desc, :boolean, null: false, default: false
+    }
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 4a5115285..9636d0e6a 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2019_08_31_022432) do
+ActiveRecord::Schema.define(version: 2019_10_09_231327) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -258,6 +258,7 @@ ActiveRecord::Schema.define(version: 2019_08_31_022432) do
     t.boolean "status_text", default: false, null: false
     t.text "custom_cw"
     t.boolean "override_cw", default: false, null: false
+    t.boolean "desc", default: false, null: false
     t.index ["account_id"], name: "index_custom_filters_on_account_id"
   end