parent
cbfa28b9cc
commit
6206f75837
@ -1,25 +1,21 @@
|
|||||||
class SearchService < BaseService
|
class SearchService < BaseService
|
||||||
def call(query, resolve = false)
|
def call(query, limit, resolve = false)
|
||||||
return if query.blank?
|
return if query.blank?
|
||||||
|
|
||||||
username, domain = query.split('@')
|
username, domain = query.split('@')
|
||||||
|
|
||||||
if domain.nil?
|
results = if domain.nil?
|
||||||
search_all(username)
|
Account.search_for(username)
|
||||||
else
|
else
|
||||||
search_or_resolve(username, domain, resolve)
|
Account.search_for("#{username} #{domain}")
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
private
|
results = results.limit(limit).with_counters
|
||||||
|
|
||||||
def search_all(username)
|
if resolve && results.empty? && !domain.nil?
|
||||||
Account.search_for(username)
|
results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")]
|
||||||
end
|
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
|
results
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in new issue