2021-04-25 01:01:43 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class AccountSuggestions::Source
|
2024-02-20 20:21:49 +11:00
|
|
|
DEFAULT_LIMIT = 10
|
|
|
|
|
2021-04-25 01:01:43 +10:00
|
|
|
def get(_account, **kwargs)
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2023-12-19 21:59:43 +11:00
|
|
|
def base_account_scope(account)
|
2024-01-13 00:09:33 +11:00
|
|
|
Account
|
|
|
|
.searchable
|
2024-03-04 17:35:20 +11:00
|
|
|
.where(discoverable: true)
|
|
|
|
.without_silenced
|
2024-08-20 01:55:42 +10:00
|
|
|
.without_memorial
|
2024-01-13 00:09:33 +11:00
|
|
|
.where.not(follows_sql, id: account.id)
|
|
|
|
.where.not(follow_requests_sql, id: account.id)
|
|
|
|
.not_excluded_by_account(account)
|
|
|
|
.not_domain_blocked_by_account(account)
|
|
|
|
.where.not(id: account.id)
|
|
|
|
.where.not(follow_recommendation_mutes_sql, id: account.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def follows_sql
|
|
|
|
<<~SQL.squish
|
|
|
|
EXISTS (SELECT 1 FROM follows WHERE follows.target_account_id = accounts.id AND follows.account_id = :id)
|
|
|
|
SQL
|
|
|
|
end
|
|
|
|
|
|
|
|
def follow_requests_sql
|
|
|
|
<<~SQL.squish
|
|
|
|
EXISTS (SELECT 1 FROM follow_requests WHERE follow_requests.target_account_id = accounts.id AND follow_requests.account_id = :id)
|
|
|
|
SQL
|
|
|
|
end
|
|
|
|
|
|
|
|
def follow_recommendation_mutes_sql
|
|
|
|
<<~SQL.squish
|
|
|
|
EXISTS (SELECT 1 FROM follow_recommendation_mutes WHERE follow_recommendation_mutes.target_account_id = accounts.id AND follow_recommendation_mutes.account_id = :id)
|
|
|
|
SQL
|
2021-04-25 01:01:43 +10:00
|
|
|
end
|
|
|
|
end
|