1
0

source.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # frozen_string_literal: true
  2. class AccountSuggestions::Source
  3. DEFAULT_LIMIT = 10
  4. def get(_account, **kwargs)
  5. raise NotImplementedError
  6. end
  7. protected
  8. def base_account_scope(account)
  9. Account
  10. .searchable
  11. .where(discoverable: true)
  12. .without_silenced
  13. .without_memorial
  14. .where.not(follows_sql, id: account.id)
  15. .where.not(follow_requests_sql, id: account.id)
  16. .not_excluded_by_account(account)
  17. .not_domain_blocked_by_account(account)
  18. .where.not(id: account.id)
  19. .where.not(follow_recommendation_mutes_sql, id: account.id)
  20. end
  21. def follows_sql
  22. <<~SQL.squish
  23. EXISTS (SELECT 1 FROM follows WHERE follows.target_account_id = accounts.id AND follows.account_id = :id)
  24. SQL
  25. end
  26. def follow_requests_sql
  27. <<~SQL.squish
  28. EXISTS (SELECT 1 FROM follow_requests WHERE follow_requests.target_account_id = accounts.id AND follow_requests.account_id = :id)
  29. SQL
  30. end
  31. def follow_recommendation_mutes_sql
  32. <<~SQL.squish
  33. EXISTS (SELECT 1 FROM follow_recommendation_mutes WHERE follow_recommendation_mutes.target_account_id = accounts.id AND follow_recommendation_mutes.account_id = :id)
  34. SQL
  35. end
  36. end