about summary refs log tree commit diff
path: root/app/models/account_suggestions.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2021-04-24 17:01:43 +0200
committerGitHub <noreply@github.com>2021-04-24 17:01:43 +0200
commitdaccc07dc170627b17564402296f6c8631d0cd97 (patch)
treebb1fea8fde8f44b622b9b39cff46026689dc30ca /app/models/account_suggestions.rb
parent863ae47b5145e53c6cc820bd7eff0efd41339e03 (diff)
Change auto-following admin-selected accounts, show in recommendations (#16078)
Diffstat (limited to 'app/models/account_suggestions.rb')
-rw-r--r--app/models/account_suggestions.rb25
1 files changed, 18 insertions, 7 deletions
diff --git a/app/models/account_suggestions.rb b/app/models/account_suggestions.rb
index 7fe9d618e..d1774e62f 100644
--- a/app/models/account_suggestions.rb
+++ b/app/models/account_suggestions.rb
@@ -1,17 +1,28 @@
 # frozen_string_literal: true
 
 class AccountSuggestions
-  class Suggestion < ActiveModelSerializers::Model
-    attributes :account, :source
-  end
+  SOURCES = [
+    AccountSuggestions::SettingSource,
+    AccountSuggestions::PastInteractionsSource,
+    AccountSuggestions::GlobalSource,
+  ].freeze
 
   def self.get(account, limit)
-    suggestions = PotentialFriendshipTracker.get(account, limit).map { |target_account| Suggestion.new(account: target_account, source: :past_interaction) }
-    suggestions.concat(FollowRecommendation.get(account, limit - suggestions.size, suggestions.map { |suggestion| suggestion.account.id }).map { |target_account| Suggestion.new(account: target_account, source: :global) }) if suggestions.size < limit
-    suggestions
+    SOURCES.each_with_object([]) do |source_class, suggestions|
+      source_suggestions = source_class.new.get(
+        account,
+        skip_account_ids: suggestions.map(&:account_id),
+        limit: limit - suggestions.size
+      )
+
+      suggestions.concat(source_suggestions)
+    end
   end
 
   def self.remove(account, target_account_id)
-    PotentialFriendshipTracker.remove(account.id, target_account_id)
+    SOURCES.each do |source_class|
+      source = source_class.new
+      source.remove(account, target_account_id)
+    end
   end
 end