2016-11-15 07:56:29 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-12 05:33:21 -08:00
|
|
|
class SearchService < BaseService
|
2016-11-12 05:49:28 -08:00
|
|
|
def call(query, limit, resolve = false)
|
2016-11-26 06:32:29 -08:00
|
|
|
return if query.blank? || query.start_with?('#')
|
2016-11-12 05:33:21 -08:00
|
|
|
|
2016-11-26 06:32:29 -08:00
|
|
|
username, domain = query.gsub(/\A@/, '').split('@')
|
2016-11-12 05:33:21 -08:00
|
|
|
|
2016-11-12 05:49:28 -08:00
|
|
|
results = if domain.nil?
|
2016-11-15 07:56:29 -08:00
|
|
|
Account.search_for(username)
|
|
|
|
else
|
|
|
|
Account.search_for("#{username} #{domain}")
|
|
|
|
end
|
2016-11-12 05:33:21 -08:00
|
|
|
|
2016-11-22 13:59:54 -08:00
|
|
|
results = results.limit(limit)
|
2016-11-12 05:33:21 -08:00
|
|
|
|
2016-11-12 05:49:28 -08:00
|
|
|
if resolve && results.empty? && !domain.nil?
|
|
|
|
results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")]
|
|
|
|
end
|
2016-11-12 05:33:21 -08:00
|
|
|
|
|
|
|
results
|
|
|
|
end
|
|
|
|
end
|