mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
23 lines
557 B
Ruby
23 lines
557 B
Ruby
# frozen_string_literal: true
|
|
|
|
class SearchService < BaseService
|
|
def call(query, limit, resolve = false)
|
|
return if query.blank?
|
|
|
|
username, domain = query.split('@')
|
|
|
|
results = if domain.nil?
|
|
Account.search_for(username)
|
|
else
|
|
Account.search_for("#{username} #{domain}")
|
|
end
|
|
|
|
results = results.limit(limit).with_counters
|
|
|
|
if resolve && results.empty? && !domain.nil?
|
|
results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")]
|
|
end
|
|
|
|
results
|
|
end
|
|
end
|