mirror of
https://github.com/mastodon/mastodon
synced 2025-04-12 00:56:38 +02:00
Fix streaming of quote posts
This commit is contained in:
parent
0ce69bd466
commit
4351856ce9
@ -6,8 +6,6 @@ class StatusCacheHydrator
|
||||
end
|
||||
|
||||
def hydrate(account_id)
|
||||
# TODO: handle quotes
|
||||
|
||||
# The cache of the serialized hash is generated by the fan-out-on-write service
|
||||
payload = Rails.cache.fetch("fan-out/#{@status.id}") { InlineRenderer.render(@status, nil, :status) }
|
||||
|
||||
@ -73,6 +71,23 @@ class StatusCacheHydrator
|
||||
payload[:bookmarked] = Bookmark.exists?(account_id: account_id, status_id: status.id)
|
||||
payload[:pinned] = StatusPin.exists?(account_id: account_id, status_id: status.id) if status.account_id == account_id
|
||||
payload[:filtered] = mapped_applied_custom_filter(account_id, status)
|
||||
payload[:quote] = hydrate_quote_payload(payload[:quote], status.quote, account_id) if payload[:quote]
|
||||
end
|
||||
|
||||
def hydrate_quote_payload(empty_payload, quote, account_id)
|
||||
# TODO: properly handle quotes, including visibility and access control
|
||||
|
||||
empty_payload.tap do |payload|
|
||||
# Nothing to do if we're in the shallow (depth limit) case
|
||||
next unless payload.key?(:quoted_status)
|
||||
|
||||
# TODO: handle hiding a rendered status or showing a non-rendered status according to visibility
|
||||
if quote&.quoted_status.nil?
|
||||
payload[:quoted_status] = nil
|
||||
elsif payload[:quoted_status].present?
|
||||
payload[:quoted_status] = StatusCacheHydrator.new(quote.quoted_status).hydrate(account_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def mapped_applied_custom_filter(account_id, status)
|
||||
|
@ -40,10 +40,119 @@ RSpec.describe StatusCacheHydrator do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when handling an unapproved quote' do
|
||||
let(:quoted_status) { Fabricate(:status) }
|
||||
|
||||
before do
|
||||
Fabricate(:quote, status: status, quoted_status: quoted_status, state: :pending)
|
||||
end
|
||||
|
||||
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 handling an approved quote' do
|
||||
let(:quoted_status) { Fabricate(:status) }
|
||||
|
||||
before do
|
||||
Fabricate(:quote, status: status, quoted_status: quoted_status, state: :accepted)
|
||||
end
|
||||
|
||||
it 'renders the same attributes as full render' do
|
||||
expect(subject).to eql(compare_to_hash)
|
||||
expect(subject[:quote]).to_not be_nil
|
||||
end
|
||||
|
||||
context 'when the quoted post has been favourited' do
|
||||
before do
|
||||
FavouriteService.new.call(account, quoted_status)
|
||||
end
|
||||
|
||||
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 has been reblogged' do
|
||||
before do
|
||||
ReblogService.new.call(account, quoted_status)
|
||||
end
|
||||
|
||||
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 matches account filters' do
|
||||
let(:quoted_status) { Fabricate(:status, text: 'this toot is about that banned word') }
|
||||
|
||||
before do
|
||||
account.custom_filters.create!(phrase: 'filter1', context: %w(home), action: :hide, keywords_attributes: [{ keyword: 'banned' }, { keyword: 'irrelevant' }])
|
||||
end
|
||||
|
||||
it 'renders the same attributes as a full render' do
|
||||
expect(subject).to eql(compare_to_hash)
|
||||
expect(subject[:quote]).to_not be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when handling a reblog' do
|
||||
let(:reblog) { Fabricate(:status) }
|
||||
let(:status) { Fabricate(:status, reblog: reblog) }
|
||||
|
||||
context 'when the reblog has an approved quote' do
|
||||
let(:quoted_status) { Fabricate(:status) }
|
||||
|
||||
before do
|
||||
Fabricate(:quote, status: reblog, quoted_status: quoted_status, state: :accepted)
|
||||
end
|
||||
|
||||
it 'renders the same attributes as full render' do
|
||||
expect(subject).to eql(compare_to_hash)
|
||||
expect(subject[:reblog][:quote]).to_not be_nil
|
||||
end
|
||||
|
||||
context 'when the quoted post has been favourited' do
|
||||
before do
|
||||
FavouriteService.new.call(account, quoted_status)
|
||||
end
|
||||
|
||||
it 'renders the same attributes as full render' do
|
||||
expect(subject).to eql(compare_to_hash)
|
||||
expect(subject[:reblog][:quote]).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the quoted post has been reblogged' do
|
||||
before do
|
||||
ReblogService.new.call(account, quoted_status)
|
||||
end
|
||||
|
||||
it 'renders the same attributes as full render' do
|
||||
expect(subject).to eql(compare_to_hash)
|
||||
expect(subject[:reblog][:quote]).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the quoted post matches account filters' do
|
||||
let(:quoted_status) { Fabricate(:status, text: 'this toot is about that banned word') }
|
||||
|
||||
before do
|
||||
account.custom_filters.create!(phrase: 'filter1', context: %w(home), action: :hide, keywords_attributes: [{ keyword: 'banned' }, { keyword: 'irrelevant' }])
|
||||
end
|
||||
|
||||
it 'renders the same attributes as a full render' do
|
||||
expect(subject).to eql(compare_to_hash)
|
||||
expect(subject[:reblog][:quote]).to_not be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it has been favourited' do
|
||||
before do
|
||||
FavouriteService.new.call(account, reblog)
|
||||
|
Loading…
x
Reference in New Issue
Block a user