mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-24 17:14:15 -05:00
b5ac61b2c5
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
51 lines
1.1 KiB
Ruby
51 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class AccountSuggestions::SettingSource < AccountSuggestions::Source
|
|
def get(account, limit: 10)
|
|
if setting_enabled?
|
|
base_account_scope(account).where(setting_to_where_condition).limit(limit).pluck(:id).zip([key].cycle)
|
|
else
|
|
[]
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def key
|
|
:featured
|
|
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)|
|
|
Arel::Nodes::Grouping.new(
|
|
Account.arel_table[:username].lower.eq(username.downcase).and(
|
|
Account.arel_table[:domain].lower.eq(domain&.downcase)
|
|
)
|
|
)
|
|
end.reduce(:or)
|
|
end
|
|
|
|
def setting_to_usernames_and_domains
|
|
setting.split(',').filter_map do |str|
|
|
username, domain = str.strip.gsub(/\A@/, '').split('@', 2)
|
|
domain = nil if TagManager.instance.local_domain?(domain)
|
|
|
|
next if username.blank?
|
|
|
|
[username.downcase, domain&.downcase]
|
|
end
|
|
end
|
|
|
|
def setting
|
|
Setting.bootstrap_timeline_accounts
|
|
end
|
|
end
|