Fix local follows, 404 in logs

This commit is contained in:
Eugen Rochko 2016-09-08 02:40:51 +02:00
parent 0f4bc56719
commit 509c18eb13
7 changed files with 28 additions and 11 deletions

View File

@ -19,12 +19,7 @@ class Api::AccountsController < ApiController
end end
def follow def follow
if @account.local?
@follow = current_user.account.follow!(@account)
else
@follow = FollowService.new.(current_user.account, @account.acct) @follow = FollowService.new.(current_user.account, @account.acct)
end
render action: :show render action: :show
end end

View File

@ -7,8 +7,21 @@ class ApplicationController < ActionController::Base
helper_method :current_account 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 protected
def not_found
respond_to do |format|
format.any { head 404 }
end
end
def current_account def current_account
current_user.try(:account) current_user.try(:account)
end end

View File

@ -8,7 +8,7 @@ class FollowRemoteAccountService < BaseService
def call(uri, subscribe = true) def call(uri, subscribe = true)
username, domain = uri.split('@') 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) account = Account.find_remote(username, domain)

View File

@ -8,7 +8,13 @@ class FollowService < BaseService
return nil if target_account.nil? return nil if target_account.nil?
follow = source_account.follow!(target_account) follow = source_account.follow!(target_account)
if target_account.local?
NotificationMailer.follow(target_account, source_account).deliver_later
else
NotificationWorker.perform_async(follow.stream_entry.id, target_account.id) 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]) source_account.ping!(account_url(source_account, format: 'atom'), [Rails.configuration.x.hub_url])
follow follow
end end

View File

@ -72,4 +72,6 @@ Rails.application.routes.draw do
end end
root 'home#index' root 'home#index'
match '*unmatched_route', via: :all, to: 'application#raise_not_found'
end end

View File

@ -7,6 +7,7 @@ RSpec.describe Api::AccountsController, type: :controller do
let(:token) { double acceptable?: true, resource_owner_id: user.id } let(:token) { double acceptable?: true, resource_owner_id: user.id }
before do before do
stub_request(:post, "https://pubsubhubbub.superfeedr.com/").to_return(:status => 200, :body => "", :headers => {})
allow(controller).to receive(:doorkeeper_token) { token } allow(controller).to receive(:doorkeeper_token) { token }
end end
@ -39,7 +40,7 @@ RSpec.describe Api::AccountsController, type: :controller do
end end
describe 'POST #follow' do describe 'POST #follow' do
let(:other_account) { Fabricate(:account, username: 'bob') } let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
before do before do
post :follow, params: { id: other_account.id } post :follow, params: { id: other_account.id }
@ -55,7 +56,7 @@ RSpec.describe Api::AccountsController, type: :controller do
end end
describe 'POST #unfollow' do describe 'POST #unfollow' do
let(:other_account) { Fabricate(:account, username: 'bob') } let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
before do before do
user.account.follow!(other_account) user.account.follow!(other_account)