Change auto-following admin-selected accounts, show in recommendations (#16078)
This commit is contained in:
parent
863ae47b51
commit
daccc07dc1
16 changed files with 228 additions and 128 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue