diff --git a/app/controllers/api/v1/filters_controller.rb b/app/controllers/api/v1/filters_controller.rb index e5ebaff4d..496964394 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, :irreversible, :whole_word, context: []) + params.permit(:phrase, :expires_in, :irreversible, :whole_word, :exclude_media, :media_only, context: []) end end diff --git a/app/controllers/filters_controller.rb b/app/controllers/filters_controller.rb index f1e110d87..2f6f98272 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, context: []) + params.require(:custom_filter).permit(:phrase, :expires_in, :irreversible, :whole_word, :exclude_media, :media_only, context: []) end def set_body_classes diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index 064903d71..bd418366c 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -206,6 +206,12 @@ class FeedManager active_filters.select! { |filter| filter.context.include?(context.to_s) && !filter.expired? } + if status.media_attachments.any? + active_filters.delete_if { |filter| filter.exclude_media } + else + active_filters.delete_if { |filter| filter.media_only } + end + active_filters.map! do |filter| if filter.whole_word sb = filter.phrase =~ /\A[[:word:]]/ ? '\b' : '' diff --git a/app/models/custom_filter.rb b/app/models/custom_filter.rb index 342207a55..d4cb2206e 100644 --- a/app/models/custom_filter.rb +++ b/app/models/custom_filter.rb @@ -3,15 +3,17 @@ # # Table name: custom_filters # -# id :bigint(8) not null, primary key -# account_id :bigint(8) -# expires_at :datetime -# phrase :text default(""), not null -# context :string default([]), not null, is an Array -# whole_word :boolean default(TRUE), not null -# irreversible :boolean default(FALSE), not null -# created_at :datetime not null -# updated_at :datetime not null +# id :bigint(8) not null, primary key +# account_id :bigint(8) +# expires_at :datetime +# phrase :text default(""), not null +# context :string default([]), not null, is an Array +# irreversible :boolean default(FALSE), not null +# created_at :datetime not null +# updated_at :datetime not null +# whole_word :boolean default(TRUE), not null +# exclude_media :boolean default(FALSE), not null +# media_only :boolean default(FALSE), not null # class CustomFilter < ApplicationRecord diff --git a/app/serializers/rest/filter_serializer.rb b/app/serializers/rest/filter_serializer.rb index 57205630b..f83d55577 100644 --- a/app/serializers/rest/filter_serializer.rb +++ b/app/serializers/rest/filter_serializer.rb @@ -2,7 +2,7 @@ class REST::FilterSerializer < ActiveModel::Serializer attributes :id, :phrase, :context, :whole_word, :expires_at, - :irreversible + :irreversible, :exclude_media, :media_only def id object.id.to_s diff --git a/app/views/filters/_fields.html.haml b/app/views/filters/_fields.html.haml index fb94a07fc..84b380f13 100644 --- a/app/views/filters/_fields.html.haml +++ b/app/views/filters/_fields.html.haml @@ -14,3 +14,7 @@ .fields-group = f.input :whole_word, wrapper: :with_label + +.fields-group + = f.input :exclude_media, wrapper: :with_label + = f.input :media_only, wrapper: :with_label diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 9e8bb6a2b..b2ef1c2a3 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -88,6 +88,8 @@ en: header: Header inbox_url: URL of the relay inbox irreversible: Drop instead of hide + exclude_media: Don't filter roars with attachments + media_only: Only filter roars with attachments locale: Interface language locked: Lock account max_uses: Max number of uses diff --git a/db/migrate/20190427232757_add_media_to_filters.rb b/db/migrate/20190427232757_add_media_to_filters.rb new file mode 100644 index 000000000..77120a263 --- /dev/null +++ b/db/migrate/20190427232757_add_media_to_filters.rb @@ -0,0 +1,8 @@ +class AddMediaToFilters < ActiveRecord::Migration[5.2] + def change + safety_assured { + add_column :custom_filters, :exclude_media, :boolean, default: false, null: false + add_column :custom_filters, :media_only, :boolean, default: false, null: false + } + end +end diff --git a/db/schema.rb b/db/schema.rb index cd028b0b8..e621feb46 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -247,6 +247,8 @@ ActiveRecord::Schema.define(version: 2019_05_19_130537) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "whole_word", default: true, null: false + t.boolean "exclude_media", default: false, null: false + t.boolean "media_only", default: false, null: false t.index ["account_id"], name: "index_custom_filters_on_account_id" end