about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorAkihiko Odaki (@fn_aki@pawoo.net) <akihiko.odaki.4i@stu.hosei.ac.jp>2017-06-23 01:34:27 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-06-22 18:34:27 +0200
commite27f792c24d1040246bc6ae890e6052f763cdb84 (patch)
treee972824755126f84735d0f8757da289c51589c90 /app
parent98fab24beada0bb681a25d9a48918f3ea903a90a (diff)
Some minor change and spec for Account (#3813)
* Introduce domains method to Account relation

Account had followers_domains method, which was excessively specific.
Let relation of Account have domains method instead.

* Move follow_mapping in Account to AccountInteractions

* Introduce shared examples for AccountAvatar inclusion

* Cover Account more
Diffstat (limited to 'app')
-rw-r--r--app/models/account.rb12
-rw-r--r--app/models/concerns/account_interactions.rb6
-rw-r--r--app/workers/pubsubhubbub/distribution_worker.rb2
3 files changed, 11 insertions, 9 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 72bad51a2..2b54cee5f 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -124,10 +124,6 @@ class Account < ApplicationRecord
     subscription_expires_at.present?
   end
 
-  def followers_domains
-    followers.reorder(nil).pluck('distinct accounts.domain')
-  end
-
   def keypair
     OpenSSL::PKey::RSA.new(private_key || public_key)
   end
@@ -163,6 +159,10 @@ class Account < ApplicationRecord
   end
 
   class << self
+    def domains
+      reorder(nil).pluck('distinct accounts.domain')
+    end
+
     def triadic_closures(account, limit: 5, offset: 0)
       sql = <<-SQL.squish
         WITH first_degree AS (
@@ -236,10 +236,6 @@ class Account < ApplicationRecord
 
       [textsearch, query]
     end
-
-    def follow_mapping(query, field)
-      query.pluck(field).each_with_object({}) { |id, mapping| mapping[id] = true }
-    end
   end
 
   before_create :generate_keys
diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account_interactions.rb
index de5979958..9ffed2910 100644
--- a/app/models/concerns/account_interactions.rb
+++ b/app/models/concerns/account_interactions.rb
@@ -29,6 +29,12 @@ module AccountInteractions
       blocked_domains = AccountDomainBlock.where(account_id: account_id, domain: accounts_map.values).pluck(:domain)
       accounts_map.map { |id, domain| [id, blocked_domains.include?(domain)] }.to_h
     end
+
+    private
+
+    def follow_mapping(query, field)
+      query.pluck(field).each_with_object({}) { |id, mapping| mapping[id] = true }
+    end
   end
 
   included do
diff --git a/app/workers/pubsubhubbub/distribution_worker.rb b/app/workers/pubsubhubbub/distribution_worker.rb
index da01dcd91..b41cec90d 100644
--- a/app/workers/pubsubhubbub/distribution_worker.rb
+++ b/app/workers/pubsubhubbub/distribution_worker.rb
@@ -33,7 +33,7 @@ class Pubsubhubbub::DistributionWorker
     return if stream_entries.empty?
 
     @payload = AtomSerializer.render(AtomSerializer.new.feed(@account, stream_entries))
-    @domains = @account.followers_domains
+    @domains = @account.followers.domains
 
     Pubsubhubbub::DeliveryWorker.push_bulk(@subscriptions.reject { |s| !allowed_to_receive?(s.callback_url) }) do |subscription|
       [subscription.id, @payload]