1
0
mirror of https://github.com/funamitech/mastodon synced 2024-12-24 11:38:37 +09:00
YuruToot/app/services/search_service.rb

24 lines
585 B
Ruby
Raw Normal View History

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