2021-04-25 01:01:43 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class AccountSuggestions::SettingSource < AccountSuggestions::Source
|
2024-02-20 20:21:49 +11:00
|
|
|
def get(account, limit: DEFAULT_LIMIT)
|
2023-12-19 21:59:43 +11:00
|
|
|
if setting_enabled?
|
2024-05-29 00:11:31 +10:00
|
|
|
base_account_scope(account).merge(setting_to_where_condition).limit(limit).pluck(:id).zip([key].cycle)
|
2023-12-19 21:59:43 +11:00
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
2021-04-25 01:01:43 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2023-12-19 21:59:43 +11:00
|
|
|
def key
|
|
|
|
:featured
|
2021-04-25 01:01:43 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
def usernames_and_domains
|
|
|
|
@usernames_and_domains ||= setting_to_usernames_and_domains
|
|
|
|
end
|
|
|
|
|
|
|
|
def setting_enabled?
|
|
|
|
setting.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def setting_to_where_condition
|
|
|
|
usernames_and_domains.map do |(username, domain)|
|
2024-05-29 00:11:31 +10:00
|
|
|
Account
|
|
|
|
.with_username(username)
|
|
|
|
.with_domain(domain)
|
2021-04-25 01:01:43 +10:00
|
|
|
end.reduce(:or)
|
|
|
|
end
|
|
|
|
|
|
|
|
def setting_to_usernames_and_domains
|
2023-05-23 18:49:12 +10:00
|
|
|
setting.split(',').filter_map do |str|
|
2021-04-25 01:01:43 +10:00
|
|
|
username, domain = str.strip.gsub(/\A@/, '').split('@', 2)
|
|
|
|
domain = nil if TagManager.instance.local_domain?(domain)
|
|
|
|
|
|
|
|
next if username.blank?
|
|
|
|
|
2023-02-10 21:14:58 +11:00
|
|
|
[username.downcase, domain&.downcase]
|
2023-05-23 18:49:12 +10:00
|
|
|
end
|
2021-04-25 01:01:43 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
def setting
|
|
|
|
Setting.bootstrap_timeline_accounts
|
|
|
|
end
|
|
|
|
end
|