about summary refs log tree commit diff
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-05-09 10:17:55 -0500
committermultiple creatures <dev@multiple-creature.party>2019-05-21 03:16:23 -0500
commita3faf5b1696a92f0e586288a2b114388eb595993 (patch)
treeaeaf677ba53cdc57167c3e901e53fd177b894247
parentc2e07ecd7f1bf5f1b1780e8c69fb15e993932eb5 (diff)
Account model: drop `protocol` attribute when looking up AP inboxes; use `remote` scope instead. If no `domain` set, use domain of `inbox_url`.
-rw-r--r--app/models/account.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 50033d1c3..e8f9f0ee9 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -35,7 +35,6 @@
 #  outbox_url              :string           default(""), not null
 #  shared_inbox_url        :string           default(""), not null
 #  followers_url           :string           default(""), not null
-#  protocol                :integer          default("ostatus"), not null
 #  memorial                :boolean          default(FALSE), not null
 #  moved_to_account_id     :bigint(8)
 #  featured_collection_url :string
@@ -125,6 +124,9 @@ class Account < ApplicationRecord
            :locale,
            :hides_network?,
            :shows_application?,
+           :always_local?,
+           :default_local?,
+           :no_blabber_blocks?,
            to: :user,
            prefix: true,
            allow_nil: true
@@ -411,7 +413,7 @@ class Account < ApplicationRecord
     end
 
     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)
     end
 
@@ -498,6 +500,7 @@ class Account < ApplicationRecord
   end
 
   before_create :generate_keys
+  before_create :set_domain_from_inbox_url
   before_validation :prepare_contents, if: :local?
   before_validation :prepare_username, on: :create
   before_destroy :clean_feed_manager
@@ -513,6 +516,13 @@ class Account < ApplicationRecord
     username&.squish!
   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
     return unless local? && !Rails.env.test?