Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix public timeline showing reblogs of unlisted posts #2724

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/models/public_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def get(limit, max_id = nil, since_id = nil, min_id = nil)

scope.merge!(without_local_only_scope) unless allow_local_only?
scope.merge!(without_replies_scope) unless with_replies?
scope.merge!(without_reblogs_scope) unless with_reblogs?
if with_reblogs?
scope.merge!(with_reblogs_of_public_scope)
else
scope.merge!(without_reblogs_scope)
end
scope.merge!(local_only_scope) if local_only?
scope.merge!(remote_only_scope) if remote_only?
scope.merge!(account_filters_scope) if account?
Expand Down Expand Up @@ -90,6 +94,10 @@ def without_reblogs_scope
Status.without_reblogs
end

def with_reblogs_of_public_scope
Status.left_outer_joins(:reblog).where(reblog: { visibility: [nil, :public] })
end

def media_only_scope
Status.joins(:media_attachments).group(:id)
end
Expand Down
14 changes: 14 additions & 0 deletions spec/models/public_feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@
expect(subject).to_not include(silenced_status.id)
end

context 'with with_reblogs option' do
subject { described_class.new(nil, with_reblogs: true).get(20).map(&:id) }

it 'lists public reblogs of public posts, but not public reblogs of unlisted posts' do
status = Fabricate(:status, visibility: :public)
boost = Fabricate(:status, reblog_of_id: status.id, visibility: :public)
unlisted_status = Fabricate(:status, visibility: :unlisted)
excluded_boost = Fabricate(:status, reblog_of_id: unlisted_status.id, visibility: :public)

expect(subject).to include(boost.id)
.and not_include(excluded_boost.id)
end
end

context 'without local_only option' do
subject { described_class.new(viewer).get(20).map(&:id) }

Expand Down