This repository has been archived on 2024-06-09. You can view files and clone it, but cannot push or open issues/pull-requests.
2016-11-15 16:56:29 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-12 14:33:21 +01:00
|
|
|
class SearchService < BaseService
|
2016-11-12 14:49:28 +01:00
|
|
|
def call(query, limit, resolve = false)
|
2016-11-12 14:33:21 +01:00
|
|
|
return if query.blank?
|
|
|
|
|
|
|
|
username, domain = query.split('@')
|
|
|
|
|
2016-11-12 14:49:28 +01:00
|
|
|
results = if domain.nil?
|
2016-11-15 16:56:29 +01:00
|
|
|
Account.search_for(username)
|
|
|
|
else
|
|
|
|
Account.search_for("#{username} #{domain}")
|
|
|
|
end
|
2016-11-12 14:33:21 +01:00
|
|
|
|
2016-11-22 22:59:54 +01:00
|
|
|
results = results.limit(limit)
|
2016-11-12 14:33:21 +01:00
|
|
|
|
2016-11-12 14:49:28 +01:00
|
|
|
if resolve && results.empty? && !domain.nil?
|
|
|
|
results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")]
|
|
|
|
end
|
2016-11-12 14:33:21 +01:00
|
|
|
|
|
|
|
results
|
|
|
|
end
|
|
|
|
end
|