Custom filters: add ability to create filters that exclude or are exclusive to roars with attachments.
parent
2423830e3c
commit
26d90a36ff
|
@ -43,6 +43,6 @@ class Api::V1::FiltersController < Api::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def resource_params
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -58,7 +58,7 @@ class FiltersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def resource_params
|
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
|
end
|
||||||
|
|
||||||
def set_body_classes
|
def set_body_classes
|
||||||
|
|
|
@ -206,6 +206,12 @@ class FeedManager
|
||||||
|
|
||||||
active_filters.select! { |filter| filter.context.include?(context.to_s) && !filter.expired? }
|
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|
|
active_filters.map! do |filter|
|
||||||
if filter.whole_word
|
if filter.whole_word
|
||||||
sb = filter.phrase =~ /\A[[:word:]]/ ? '\b' : ''
|
sb = filter.phrase =~ /\A[[:word:]]/ ? '\b' : ''
|
||||||
|
|
|
@ -3,15 +3,17 @@
|
||||||
#
|
#
|
||||||
# Table name: custom_filters
|
# Table name: custom_filters
|
||||||
#
|
#
|
||||||
# id :bigint(8) not null, primary key
|
# id :bigint(8) not null, primary key
|
||||||
# account_id :bigint(8)
|
# account_id :bigint(8)
|
||||||
# expires_at :datetime
|
# expires_at :datetime
|
||||||
# phrase :text default(""), not null
|
# phrase :text default(""), not null
|
||||||
# context :string default([]), not null, is an Array
|
# context :string default([]), not null, is an Array
|
||||||
# whole_word :boolean default(TRUE), not null
|
# irreversible :boolean default(FALSE), not null
|
||||||
# irreversible :boolean default(FALSE), not null
|
# created_at :datetime not null
|
||||||
# created_at :datetime not null
|
# updated_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
|
class CustomFilter < ApplicationRecord
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
class REST::FilterSerializer < ActiveModel::Serializer
|
class REST::FilterSerializer < ActiveModel::Serializer
|
||||||
attributes :id, :phrase, :context, :whole_word, :expires_at,
|
attributes :id, :phrase, :context, :whole_word, :expires_at,
|
||||||
:irreversible
|
:irreversible, :exclude_media, :media_only
|
||||||
|
|
||||||
def id
|
def id
|
||||||
object.id.to_s
|
object.id.to_s
|
||||||
|
|
|
@ -14,3 +14,7 @@
|
||||||
|
|
||||||
.fields-group
|
.fields-group
|
||||||
= f.input :whole_word, wrapper: :with_label
|
= f.input :whole_word, wrapper: :with_label
|
||||||
|
|
||||||
|
.fields-group
|
||||||
|
= f.input :exclude_media, wrapper: :with_label
|
||||||
|
= f.input :media_only, wrapper: :with_label
|
||||||
|
|
|
@ -88,6 +88,8 @@ en:
|
||||||
header: Header
|
header: Header
|
||||||
inbox_url: URL of the relay inbox
|
inbox_url: URL of the relay inbox
|
||||||
irreversible: Drop instead of hide
|
irreversible: Drop instead of hide
|
||||||
|
exclude_media: Don't filter roars with attachments
|
||||||
|
media_only: Only filter roars with attachments
|
||||||
locale: Interface language
|
locale: Interface language
|
||||||
locked: Lock account
|
locked: Lock account
|
||||||
max_uses: Max number of uses
|
max_uses: Max number of uses
|
||||||
|
|
|
@ -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
|
|
@ -247,6 +247,8 @@ ActiveRecord::Schema.define(version: 2019_05_19_130537) do
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.boolean "whole_word", default: true, 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"
|
t.index ["account_id"], name: "index_custom_filters_on_account_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue