Fix filter handling in status cache hydration (#19963)

This commit is contained in:
Claire 2022-11-07 19:47:48 +01:00 committed by GitHub
parent 106648b456
commit 3114c826a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View file

@ -19,7 +19,7 @@ class StatusCacheHydrator
payload[:muted] = false payload[:muted] = false
payload[:bookmarked] = false payload[:bookmarked] = false
payload[:pinned] = false if @status.account_id == account_id payload[:pinned] = false if @status.account_id == account_id
payload[:filtered] = CustomFilter.apply_cached_filters(CustomFilter.cached_filters_for(@status.reblog_of_id), @status.reblog).map { |filter| ActiveModelSerializers::SerializableResource.new(filter, serializer: REST::FilterResultSerializer).as_json } payload[:filtered] = CustomFilter.apply_cached_filters(CustomFilter.cached_filters_for(account_id), @status.reblog).map { |filter| ActiveModelSerializers::SerializableResource.new(filter, serializer: REST::FilterResultSerializer).as_json }
# If the reblogged status is being delivered to the author who disabled the display of the application # If the reblogged status is being delivered to the author who disabled the display of the application
# used to create the status, we need to hydrate it here too # used to create the status, we need to hydrate it here too
@ -51,7 +51,7 @@ class StatusCacheHydrator
payload[:muted] = ConversationMute.where(account_id: account_id, conversation_id: @status.conversation_id).exists? payload[:muted] = ConversationMute.where(account_id: account_id, conversation_id: @status.conversation_id).exists?
payload[:bookmarked] = Bookmark.where(account_id: account_id, status_id: @status.id).exists? payload[:bookmarked] = Bookmark.where(account_id: account_id, status_id: @status.id).exists?
payload[:pinned] = StatusPin.where(account_id: account_id, status_id: @status.id).exists? if @status.account_id == account_id payload[:pinned] = StatusPin.where(account_id: account_id, status_id: @status.id).exists? if @status.account_id == account_id
payload[:filtered] = CustomFilter.apply_cached_filters(CustomFilter.cached_filters_for(@status.id), @status).map { |filter| ActiveModelSerializers::SerializableResource.new(filter, serializer: REST::FilterResultSerializer).as_json } payload[:filtered] = CustomFilter.apply_cached_filters(CustomFilter.cached_filters_for(account_id), @status).map { |filter| ActiveModelSerializers::SerializableResource.new(filter, serializer: REST::FilterResultSerializer).as_json }
if payload[:poll] if payload[:poll]
payload[:poll][:voted] = @status.account_id == account_id payload[:poll][:voted] = @status.account_id == account_id

View file

@ -28,6 +28,18 @@ describe StatusCacheHydrator do
end end
end end
context 'when handling a filtered status' do
let(: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)
end
end
context 'when handling a reblog' do context 'when handling a reblog' do
let(:reblog) { Fabricate(:status) } let(:reblog) { Fabricate(:status) }
let(:status) { Fabricate(:status, reblog: reblog) } let(:status) { Fabricate(:status, reblog: reblog) }
@ -99,6 +111,18 @@ describe StatusCacheHydrator do
expect(subject).to eql(compare_to_hash) expect(subject).to eql(compare_to_hash)
end end
end end
context 'that matches account filters' do
let(:reblog) { 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)
end
end
end end
end end