Handle stream_entry URL correctly in ActivityPub (#4854)

In before, the method uses stream_entry id as status id, so replied status was wrongly selected.

This PR uses StatusFinder which was introduced with `Api::Web::EmbedsController`.
This commit is contained in:
unarist 2017-09-09 01:20:03 +09:00 committed by Eugen Rochko
parent dabc309ca3
commit a12572e074
2 changed files with 30 additions and 2 deletions

View File

@ -96,12 +96,14 @@ class ActivityPub::TagManager
when 'Account' when 'Account'
klass.find_local(uri_to_local_id(uri, :username)) klass.find_local(uri_to_local_id(uri, :username))
else else
klass.find_by(id: uri_to_local_id(uri)) StatusFinder.new(uri).status
end end
elsif ::TagManager.instance.local_id?(uri) elsif ::TagManager.instance.local_id?(uri)
klass.find_by(id: ::TagManager.instance.unique_tag_to_local_id(uri, klass.to_s)) klass.find_by(id: ::TagManager.instance.unique_tag_to_local_id(uri, klass.to_s))
else else
klass.find_by(uri: uri.split('#').first) klass.find_by(uri: uri.split('#').first)
end end
rescue ActiveRecord::RecordNotFound
nil
end end
end end

View File

@ -91,9 +91,35 @@ RSpec.describe ActivityPub::TagManager do
end end
describe '#uri_to_resource' do describe '#uri_to_resource' do
it 'returns the local resource' do it 'returns the local account' do
account = Fabricate(:account) account = Fabricate(:account)
expect(subject.uri_to_resource(subject.uri_for(account), Account)).to eq account expect(subject.uri_to_resource(subject.uri_for(account), Account)).to eq account
end end
it 'returns the remote account by matching URI without fragment part' do
account = Fabricate(:account, uri: 'https://example.com/123')
expect(subject.uri_to_resource('https://example.com/123#456', Account)).to eq account
end
it 'returns the local status for ActivityPub URI' do
status = Fabricate(:status)
expect(subject.uri_to_resource(subject.uri_for(status), Status)).to eq status
end
it 'returns the local status for OStatus tag: URI' do
status = Fabricate(:status)
expect(subject.uri_to_resource(::TagManager.instance.uri_for(status), Status)).to eq status
end
it 'returns the local status for OStatus StreamEntry URL' do
status = Fabricate(:status)
stream_entry_url = account_stream_entry_url(status.account, status.stream_entry)
expect(subject.uri_to_resource(stream_entry_url, Status)).to eq status
end
it 'returns the remote status by matching URI without fragment part' do
status = Fabricate(:status, uri: 'https://example.com/123')
expect(subject.uri_to_resource('https://example.com/123#456', Status)).to eq status
end
end end
end end