diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/api/v1/filters_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/filters_controller.rb | 2 | ||||
-rw-r--r-- | app/lib/feed_manager.rb | 6 | ||||
-rw-r--r-- | app/models/custom_filter.rb | 20 | ||||
-rw-r--r-- | app/serializers/rest/filter_serializer.rb | 2 | ||||
-rw-r--r-- | app/views/filters/_fields.html.haml | 4 |
6 files changed, 24 insertions, 12 deletions
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 |