mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-13 19:54:01 -05:00
22 lines
486 B
Ruby
22 lines
486 B
Ruby
class SearchService < BaseService
|
|
def call(query, limit, resolve = false)
|
|
return if query.blank?
|
|
|
|
username, domain = query.split('@')
|
|
|
|
results = if domain.nil?
|
|
Account.search_for(username)
|
|
else
|
|
Account.search_for("#{username} #{domain}")
|
|
end
|
|
|
|
results = results.limit(limit).with_counters
|
|
|
|
if resolve && results.empty? && !domain.nil?
|
|
results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")]
|
|
end
|
|
|
|
results
|
|
end
|
|
end
|