gearheads
/
mastodon
Archived
2
0
Fork 0
This repository has been archived on 2024-06-09. You can view files and clone it, but cannot push or open issues/pull-requests.
mastodon/app/services/search_service.rb

26 lines
571 B
Ruby
Raw Normal View History

class SearchService < BaseService
def call(query, resolve = false)
return if query.blank?
username, domain = query.split('@')
if domain.nil?
search_all(username)
else
search_or_resolve(username, domain, resolve)
end
end
private
def search_all(username)
Account.search_for(username)
end
def search_or_resolve(username, domain, resolve)
results = Account.search_for("#{username} #{domain}")
return [FollowRemoteAccountService.new.call("#{username}@#{domain}")] if results.empty? && resolve
results
end
end