about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
Diffstat (limited to 'app/services')
-rw-r--r--app/services/search_service.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/services/search_service.rb b/app/services/search_service.rb
new file mode 100644
index 000000000..d9b627853
--- /dev/null
+++ b/app/services/search_service.rb
@@ -0,0 +1,25 @@
+class SearchService < BaseService
+  def call(query, resolve = false)
+    return if query.blank?
+
+    username, domain = query.split('@')
+
+    if domain.nil?
+      search_all(username)
+    else
+      search_or_resolve(username, domain, resolve)
+    end
+  end
+
+  private
+
+  def search_all(username)
+    Account.search_for(username)
+  end
+
+  def search_or_resolve(username, domain, resolve)
+    results = Account.search_for("#{username} #{domain}")
+    return [FollowRemoteAccountService.new.call("#{username}@#{domain}")] if results.empty? && resolve
+    results
+  end
+end