mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-24 01:08:08 +01:00
6cdcac1396
overshadow requirement for remote-lookup
26 lines
764 B
Ruby
26 lines
764 B
Ruby
# frozen_string_literal: true
|
|
|
|
class SearchService < BaseService
|
|
def call(query, limit, resolve = false)
|
|
return if query.blank? || query.start_with?('#')
|
|
|
|
username, domain = query.gsub(/\A@/, '').split('@')
|
|
|
|
if domain.nil?
|
|
exact_match = Account.find_local(username)
|
|
results = Account.search_for(username)
|
|
else
|
|
exact_match = Account.find_remote(username, domain)
|
|
results = Account.search_for("#{username} #{domain}")
|
|
end
|
|
|
|
results = results.limit(limit).to_a
|
|
results = [exact_match] + results.reject { |a| a.id == exact_match.id } if exact_match
|
|
|
|
if resolve && !exact_match && !domain.nil?
|
|
results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")]
|
|
end
|
|
|
|
results
|
|
end
|
|
end
|