Account model: drop `protocol` attribute when looking up AP inboxes; use `remote` scope instead. If no `domain` set, use domain of `inbox_url`.

staging
multiple creatures 2019-05-09 10:17:55 -05:00
parent c2e07ecd7f
commit a3faf5b169
1 changed files with 12 additions and 2 deletions

View File

@ -35,7 +35,6 @@
# outbox_url :string default(""), not null # outbox_url :string default(""), not null
# shared_inbox_url :string default(""), not null # shared_inbox_url :string default(""), not null
# followers_url :string default(""), not null # followers_url :string default(""), not null
# protocol :integer default("ostatus"), not null
# memorial :boolean default(FALSE), not null # memorial :boolean default(FALSE), not null
# moved_to_account_id :bigint(8) # moved_to_account_id :bigint(8)
# featured_collection_url :string # featured_collection_url :string
@ -125,6 +124,9 @@ class Account < ApplicationRecord
:locale, :locale,
:hides_network?, :hides_network?,
:shows_application?, :shows_application?,
:always_local?,
:default_local?,
:no_blabber_blocks?,
to: :user, to: :user,
prefix: true, prefix: true,
allow_nil: true allow_nil: true
@ -411,7 +413,7 @@ class Account < ApplicationRecord
end end
def inboxes def inboxes
urls = reorder(nil).where(protocol: :activitypub).pluck(Arel.sql("distinct coalesce(nullif(accounts.shared_inbox_url, ''), accounts.inbox_url)")) urls = reorder(nil).remote.pluck(Arel.sql("distinct coalesce(nullif(accounts.shared_inbox_url, ''), accounts.inbox_url)"))
DeliveryFailureTracker.filter(urls) DeliveryFailureTracker.filter(urls)
end end
@ -498,6 +500,7 @@ class Account < ApplicationRecord
end end
before_create :generate_keys before_create :generate_keys
before_create :set_domain_from_inbox_url
before_validation :prepare_contents, if: :local? before_validation :prepare_contents, if: :local?
before_validation :prepare_username, on: :create before_validation :prepare_username, on: :create
before_destroy :clean_feed_manager before_destroy :clean_feed_manager
@ -513,6 +516,13 @@ class Account < ApplicationRecord
username&.squish! username&.squish!
end end
def set_domain_from_inbox_url
return if domain.present? || inbox_url.blank?
self.domain = Addressable::URI.parse(inbox_url).domain
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
nil
end
def generate_keys def generate_keys
return unless local? && !Rails.env.test? return unless local? && !Rails.env.test?