Custom filters: add ability to create filters that exclude or are exclusive to roars with attachments.

staging
multiple creatures 2019-04-27 19:19:32 -05:00
parent 2423830e3c
commit 26d90a36ff
9 changed files with 36 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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' : ''

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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