about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/api/accounts_controller.rb7
-rw-r--r--app/controllers/application_controller.rb13
-rw-r--r--app/services/follow_remote_account_service.rb2
-rw-r--r--app/services/follow_service.rb8
4 files changed, 22 insertions, 8 deletions
diff --git a/app/controllers/api/accounts_controller.rb b/app/controllers/api/accounts_controller.rb
index 8c4da5270..4a4431b2d 100644
--- a/app/controllers/api/accounts_controller.rb
+++ b/app/controllers/api/accounts_controller.rb
@@ -19,12 +19,7 @@ class Api::AccountsController < ApiController
   end
 
   def follow
-    if @account.local?
-      @follow = current_user.account.follow!(@account)
-    else
-      @follow = FollowService.new.(current_user.account, @account.acct)
-    end
-
+    @follow = FollowService.new.(current_user.account, @account.acct)
     render action: :show
   end
 
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 73de1838c..90e923951 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -7,8 +7,21 @@ class ApplicationController < ActionController::Base
 
   helper_method :current_account
 
+  rescue_from ActionController::RoutingError, with: :not_found
+  rescue_from ActiveRecord::RecordNotFound, with: :not_found
+
+  def raise_not_found
+    raise ActionController::RoutingError.new("No route matches #{params[:unmatched_route]}")
+  end
+
   protected
 
+  def not_found
+    respond_to do |format|
+      format.any { head 404 }
+    end
+  end
+
   def current_account
     current_user.try(:account)
   end
diff --git a/app/services/follow_remote_account_service.rb b/app/services/follow_remote_account_service.rb
index f05668420..c4330d7cf 100644
--- a/app/services/follow_remote_account_service.rb
+++ b/app/services/follow_remote_account_service.rb
@@ -8,7 +8,7 @@ class FollowRemoteAccountService < BaseService
   def call(uri, subscribe = true)
     username, domain = uri.split('@')
 
-    return Account.find_local(username) if domain == Rails.configuration.x.local_domain
+    return Account.find_local(username) if domain == Rails.configuration.x.local_domain || domain.nil?
 
     account = Account.find_remote(username, domain)
 
diff --git a/app/services/follow_service.rb b/app/services/follow_service.rb
index 06bbfa8f0..e4a4bfcd3 100644
--- a/app/services/follow_service.rb
+++ b/app/services/follow_service.rb
@@ -8,7 +8,13 @@ class FollowService < BaseService
     return nil if target_account.nil?
 
     follow = source_account.follow!(target_account)
-    NotificationWorker.perform_async(follow.stream_entry.id, target_account.id)
+
+    if target_account.local?
+      NotificationMailer.follow(target_account, source_account).deliver_later
+    else
+      NotificationWorker.perform_async(follow.stream_entry.id, target_account.id)
+    end
+
     source_account.ping!(account_url(source_account, format: 'atom'), [Rails.configuration.x.hub_url])
     follow
   end