Skip to content

Commit

Permalink
Fix: #636 投稿削除時エラーが出る場合がある問題 (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode authored Mar 5, 2024
1 parent 8cb4838 commit 82a8026
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/services/remove_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def call(status, **options)
@account = status.account
@options = options

@visibility = @status.visibility&.to_sym || :public
@searchability = @status.searchability&.to_sym || @status.compute_searchability&.to_sym || :public

with_redis_lock("distribute:#{@status.id}") do
@status.discard_with_reblogs

Expand Down Expand Up @@ -146,7 +149,7 @@ def remove_from_hashtags
featured_tag.decrement(@status.id)
end

return unless %i(public public_unlisted login).include?(@status.visibility.to_sym) || (@status.unlisted_visibility? && %i(public public_unlisted).include?(@status.searchability.to_sym))
return unless %i(public public_unlisted login).include?(@visibility) || (@status.unlisted_visibility? && %i(public public_unlisted).include?(@searchability))

return if skip_streaming?

Expand All @@ -157,7 +160,7 @@ def remove_from_hashtags
end

def remove_from_public
return unless %i(public public_unlisted login).include?(@status.visibility.to_sym)
return unless %i(public public_unlisted login).include?(@visibility)

return if skip_streaming?

Expand All @@ -166,7 +169,7 @@ def remove_from_public
end

def remove_from_media
return unless %i(public public_unlisted login).include?(@status.visibility.to_sym)
return unless %i(public public_unlisted login).include?(@visibility)

return if skip_streaming?

Expand Down
12 changes: 12 additions & 0 deletions spec/services/remove_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@
end
end

context 'when removed status is null-searchability' do
let(:status) { PostStatusService.new.call(alice, visibility: 'unlisted', text: 'Public post') }

before do
status.update!(searchability: nil)
end

it 'does not throw error' do
expect { subject.call(status) }.to_not raise_error
end
end

context 'when removed status is limited' do
let(:status) { PostStatusService.new.call(alice, visibility: 'mutual', text: 'limited post') }

Expand Down

0 comments on commit 82a8026

Please sign in to comment.