闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
585 B

  1. # frozen_string_literal: true
  2. class SearchService < BaseService
  3. def call(query, limit, resolve = false)
  4. return if query.blank? || query.start_with?('#')
  5. username, domain = query.gsub(/\A@/, '').split('@')
  6. results = if domain.nil?
  7. Account.search_for(username)
  8. else
  9. Account.search_for("#{username} #{domain}")
  10. end
  11. results = results.limit(limit)
  12. if resolve && results.empty? && !domain.nil?
  13. results = [FollowRemoteAccountService.new.call("#{username}@#{domain}")]
  14. end
  15. results
  16. end
  17. end