Add exclude_follows, exclude_localusers settings to custom_filter
This commit is contained in:
parent
fb9dbfc866
commit
5a0483ed21
15 changed files with 77 additions and 22 deletions
|
@ -265,7 +265,7 @@ module AccountInteractions
|
|||
|
||||
def status_matches_filters(status)
|
||||
active_filters = CustomFilter.cached_filters_for(id)
|
||||
CustomFilter.apply_cached_filters(active_filters, status)
|
||||
CustomFilter.apply_cached_filters(active_filters, status, following?(status.account))
|
||||
end
|
||||
|
||||
def followers_for_local_distribution
|
||||
|
|
|
@ -4,14 +4,16 @@
|
|||
#
|
||||
# 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
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# action :integer default("warn"), 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
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# action :integer default("warn"), not null
|
||||
# exclude_follows :boolean default(FALSE), not null
|
||||
# exclude_localusers :boolean default(FALSE), not null
|
||||
#
|
||||
|
||||
class CustomFilter < ApplicationRecord
|
||||
|
@ -94,8 +96,11 @@ class CustomFilter < ApplicationRecord
|
|||
active_filters.select { |custom_filter, _| !custom_filter.expired? }
|
||||
end
|
||||
|
||||
def self.apply_cached_filters(cached_filters, status)
|
||||
def self.apply_cached_filters(cached_filters, status, following)
|
||||
cached_filters.filter_map do |filter, rules|
|
||||
next if filter.exclude_follows && following
|
||||
next if filter.exclude_localusers && status.account.local?
|
||||
|
||||
match = rules[:keywords].match(status.proper.searchable_text) if rules[:keywords].present?
|
||||
keyword_matches = [match.to_s] unless match.nil?
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
# id :bigint(8) not null, primary key
|
||||
# custom_filter_id :bigint(8) not null
|
||||
# keyword :text default(""), not null
|
||||
# whole_word :boolean default(TRUE), not null
|
||||
# whole_word :boolean default(FALSE), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue