Fix quote post streaming edge cases (#34957)
This commit is contained in:
parent
c09f9a93f1
commit
86627624f1
2 changed files with 54 additions and 16 deletions
|
@ -75,25 +75,29 @@ class StatusCacheHydrator
|
||||||
end
|
end
|
||||||
|
|
||||||
def hydrate_quote_payload(empty_payload, quote, account_id, nested: false)
|
def hydrate_quote_payload(empty_payload, quote, account_id, nested: false)
|
||||||
empty_payload.tap do |payload|
|
return unless quote&.acceptable?
|
||||||
# Nothing to do if we're in the shallow (depth limit) case
|
|
||||||
next unless payload.key?(:quoted_status)
|
|
||||||
|
|
||||||
|
empty_payload.tap do |payload|
|
||||||
payload.delete(:quoted_status) if nested
|
payload.delete(:quoted_status) if nested
|
||||||
|
|
||||||
# TODO: performance improvements
|
# TODO: performance improvements
|
||||||
if quote&.quoted_status.nil?
|
if quote.accepted?
|
||||||
payload[nested ? :quoted_status_id : :quoted_status] = nil
|
if quote.quoted_status.nil?
|
||||||
payload[:state] = 'deleted'
|
payload[nested ? :quoted_status_id : :quoted_status] = nil
|
||||||
elsif StatusFilter.new(quote.quoted_status, Account.find_by(id: account_id)).filtered?
|
payload[:state] = 'deleted'
|
||||||
payload[nested ? :quoted_status_id : :quoted_status] = nil
|
elsif StatusFilter.new(quote.quoted_status, Account.find_by(id: account_id)).filtered?
|
||||||
payload[:state] = 'unauthorized'
|
payload[nested ? :quoted_status_id : :quoted_status] = nil
|
||||||
elsif payload[:state] == 'accepted'
|
payload[:state] = 'unauthorized'
|
||||||
if nested
|
|
||||||
payload[:quoted_status_id] = quote.quoted_status_id&.to_s
|
|
||||||
else
|
else
|
||||||
payload[:quoted_status] = StatusCacheHydrator.new(quote.quoted_status).hydrate(account_id, nested: true)
|
payload[:state] = 'accepted'
|
||||||
|
if nested
|
||||||
|
payload[:quoted_status_id] = quote.quoted_status_id&.to_s
|
||||||
|
else
|
||||||
|
payload[:quoted_status] = StatusCacheHydrator.new(quote.quoted_status).hydrate(account_id, nested: true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
payload[nested ? :quoted_status_id : :quoted_status] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,9 +56,10 @@ RSpec.describe StatusCacheHydrator do
|
||||||
|
|
||||||
context 'when handling an approved quote' do
|
context 'when handling an approved quote' do
|
||||||
let(:quoted_status) { Fabricate(:status) }
|
let(:quoted_status) { Fabricate(:status) }
|
||||||
|
let(:legacy) { false }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Fabricate(:quote, status: status, quoted_status: quoted_status, state: :accepted)
|
Fabricate(:quote, status: status, quoted_status: quoted_status, state: :accepted, legacy: legacy)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders the same attributes as full render' do
|
it 'renders the same attributes as full render' do
|
||||||
|
@ -75,13 +76,46 @@ RSpec.describe StatusCacheHydrator do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when the quote post is a legacy quote' do
|
||||||
|
let(:legacy) { true }
|
||||||
|
|
||||||
|
it 'renders the same attributes as full render' do
|
||||||
|
expect(subject).to eql(compare_to_hash)
|
||||||
|
expect(subject[:quote]).to_not be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the quoted post is a private post the viewer is not authorized to see' do
|
||||||
|
let(:quoted_status) { Fabricate(:status, account: status.account, visibility: :private) }
|
||||||
|
|
||||||
|
it 'renders the same attributes as full render' do
|
||||||
|
expect(subject).to eql(compare_to_hash)
|
||||||
|
expect(subject[:quote]).to_not be_nil
|
||||||
|
expect(subject[:quote][:quoted_status]).to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the quoted post is a private post the viewer is authorized to see' do
|
||||||
|
let(:quoted_status) { Fabricate(:status, account: status.account, visibility: :private) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
account.follow!(quoted_status.account)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders the same attributes as full render' do
|
||||||
|
expect(subject).to eql(compare_to_hash)
|
||||||
|
expect(subject[:quote]).to_not be_nil
|
||||||
|
expect(subject[:quote][:quoted_status]).to_not be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when the quoted post has been deleted' do
|
context 'when the quoted post has been deleted' do
|
||||||
let(:quoted_status) { nil }
|
let(:quoted_status) { nil }
|
||||||
|
|
||||||
it 'returns the same attributes as full render' do
|
it 'returns the same attributes as full render' do
|
||||||
expect(subject).to eql(compare_to_hash)
|
expect(subject).to eql(compare_to_hash)
|
||||||
expect(subject[:quote]).to_not be_nil
|
expect(subject[:quote]).to_not be_nil
|
||||||
expect(subject[:quote_status]).to be_nil
|
expect(subject[:quote][:quoted_status]).to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -93,7 +127,7 @@ RSpec.describe StatusCacheHydrator do
|
||||||
it 'returns the same attributes as full render' do
|
it 'returns the same attributes as full render' do
|
||||||
expect(subject).to eql(compare_to_hash)
|
expect(subject).to eql(compare_to_hash)
|
||||||
expect(subject[:quote]).to_not be_nil
|
expect(subject[:quote]).to_not be_nil
|
||||||
expect(subject[:quote_status]).to be_nil
|
expect(subject[:quote][:quoted_status]).to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue