Add stl antenna mode
This commit is contained in:
parent
551a676161
commit
7d237611d9
8 changed files with 38 additions and 4 deletions
|
@ -22,6 +22,7 @@
|
|||
# exclude_domains :jsonb
|
||||
# exclude_accounts :jsonb
|
||||
# exclude_tags :jsonb
|
||||
# stl :boolean default(FALSE), not null
|
||||
#
|
||||
class Antenna < ApplicationRecord
|
||||
include Expireable
|
||||
|
@ -33,6 +34,7 @@ class Antenna < ApplicationRecord
|
|||
belongs_to :account
|
||||
belongs_to :list, optional: true
|
||||
|
||||
scope :stls, -> { where(stl: true) }
|
||||
scope :all_keywords, -> { where(any_keywords: true) }
|
||||
scope :all_domains, -> { where(any_domains: true) }
|
||||
scope :all_accounts, -> { where(any_accounts: true) }
|
||||
|
@ -41,6 +43,8 @@ class Antenna < ApplicationRecord
|
|||
|
||||
validate :list_owner
|
||||
|
||||
before_save :check_stl_mode
|
||||
|
||||
def list_owner
|
||||
raise Mastodon::ValidationError, I18n.t('antennas.errors.invalid_list_owner') if !list_id.zero? && list.present? && list.account != account
|
||||
end
|
||||
|
@ -208,4 +212,16 @@ class Antenna < ApplicationRecord
|
|||
end
|
||||
self[:exclude_accounts] = accounts
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_stl_mode
|
||||
self[:stl] = stl_mode?
|
||||
end
|
||||
|
||||
def stl_mode?
|
||||
list_id.zero? && !any_domains && any_accounts && any_keywords && any_tags &&
|
||||
exclude_accounts.blank? && exclude_domains.blank? && exclude_keywords.blank? && exclude_tags.blank? &&
|
||||
antenna_domains.count == 1 && antenna_domains.first.name == Rails.configuration.x.local_domain
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue