gearheads
/
mastodon
Archived
2
0
Fork 0
This repository has been archived on 2024-06-09. You can view files and clone it, but cannot push or open issues/pull-requests.
mastodon/app/services/search_service.rb

24 lines
543 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class SearchService < BaseService
2016-11-12 14:49:28 +01:00
def call(query, limit, resolve = false)
return if query.blank?
username, domain = query.split('@')
2016-11-12 14:49:28 +01:00
results = if domain.nil?
Account.search_for(username)
else
Account.search_for("#{username} #{domain}")
end
results = results.limit(limit)
2016-11-12 14:49:28 +01:00
if resolve && results.empty? && !domain.nil?
results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")]
end
results
end
end