0
0
Fork 0

Change auto-following admin-selected accounts, show in recommendations (#16078)

This commit is contained in:
Eugen Rochko 2021-04-24 17:01:43 +02:00 committed by GitHub
parent 863ae47b51
commit daccc07dc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 228 additions and 128 deletions

View file

@ -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