diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2021-04-24 17:01:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-24 17:01:43 +0200 |
commit | daccc07dc170627b17564402296f6c8631d0cd97 (patch) | |
tree | bb1fea8fde8f44b622b9b39cff46026689dc30ca /app/models/account_suggestions/source.rb | |
parent | 863ae47b5145e53c6cc820bd7eff0efd41339e03 (diff) |
Change auto-following admin-selected accounts, show in recommendations (#16078)
Diffstat (limited to 'app/models/account_suggestions/source.rb')
-rw-r--r-- | app/models/account_suggestions/source.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/app/models/account_suggestions/source.rb b/app/models/account_suggestions/source.rb new file mode 100644 index 000000000..bd1068d20 --- /dev/null +++ b/app/models/account_suggestions/source.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class AccountSuggestions::Source + def key + raise NotImplementedError + end + + def get(_account, **kwargs) + raise NotImplementedError + end + + def remove(_account, target_account_id) + raise NotImplementedError + end + + protected + + def as_ordered_suggestions(scope, ordered_list) + return [] if ordered_list.empty? + + map = scope.index_by(&method(:to_ordered_list_key)) + + ordered_list.map { |ordered_list_key| map[ordered_list_key] }.compact.map do |account| + AccountSuggestions::Suggestion.new( + account: account, + source: key + ) + end + end + + def to_ordered_list_key(_account) + raise NotImplementedError + end +end |