This repository has been archived on 2024-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
2016-11-12 08:33:21 -05:00
|
|
|
class SearchService < BaseService
|
2016-11-12 08:49:28 -05:00
|
|
|
def call(query, limit, resolve = false)
|
2016-11-12 08:33:21 -05:00
|
|
|
return if query.blank?
|
|
|
|
|
|
|
|
username, domain = query.split('@')
|
|
|
|
|
2016-11-12 08:49:28 -05:00
|
|
|
results = if domain.nil?
|
|
|
|
Account.search_for(username)
|
2016-11-12 08:33:21 -05:00
|
|
|
else
|
2016-11-12 08:49:28 -05:00
|
|
|
Account.search_for("#{username} #{domain}")
|
2016-11-12 08:33:21 -05:00
|
|
|
end
|
|
|
|
|
2016-11-12 08:49:28 -05:00
|
|
|
results = results.limit(limit).with_counters
|
2016-11-12 08:33:21 -05:00
|
|
|
|
2016-11-12 08:49:28 -05:00
|
|
|
if resolve && results.empty? && !domain.nil?
|
|
|
|
results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")]
|
|
|
|
end
|
2016-11-12 08:33:21 -05:00
|
|
|
|
|
|
|
results
|
|
|
|
end
|
|
|
|
end
|