Skip to content

Commit

Permalink
Change: #844 searchableByに意図しない値が入っていたときの挙動 (#862)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode authored Oct 1, 2024
1 parent 7a6ec36 commit 294acdf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
7 changes: 4 additions & 3 deletions app/lib/activitypub/parser/status_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def audience_cc
def audience_searchable_by
return nil if @object['searchableBy'].nil?

@audience_searchable_by = as_array(@object['searchableBy']).map { |x| value_or_id(x) }
@audience_searchable_by = as_array(@object['searchableBy']).map { |x| value_or_id(x) }.compact_blank
end

def summary_language_map?
Expand Down Expand Up @@ -204,17 +204,18 @@ def searchability_from_bio

def searchability_from_audience
return nil if audience_searchable_by.blank?
return :limited if audience_searchable_by.include?('kmyblue:Limited') || audience_searchable_by.include?('as:Limited')

if audience_searchable_by.any? { |uri| ActivityPub::TagManager.instance.public_collection?(uri) }
:public
elsif audience_searchable_by.include?('kmyblue:Limited') || audience_searchable_by.include?('as:Limited')
:limited
elsif audience_searchable_by.include?('kmyblue:LocalPublic') && @friend
:public_unlisted
elsif audience_searchable_by.include?(@account.followers_url)
:private
elsif audience_searchable_by.include?(@account.uri) || audience_searchable_by.include?(@account.url)
:direct
else
:limited
end
end
end
10 changes: 6 additions & 4 deletions app/services/activitypub/process_account_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def url
def audience_searchable_by
return nil if @json['searchableBy'].nil?

@audience_searchable_by_processaccountservice = as_array(@json['searchableBy']).map { |x| value_or_id(x) }
@audience_searchable_by_processaccountservice = as_array(@json['searchableBy']).map { |x| value_or_id(x) }.compact_blank
end

def searchability_from_audience
Expand All @@ -289,14 +289,16 @@ def searchability_from_audience
return invalid_subscription_software? ? misskey_searchability_from_indexable : :direct
end

return :limited if audience_searchable_by.include?('kmyblue:Limited') || audience_searchable_by.include?('as:Limited')

if audience_searchable_by.any? { |uri| ActivityPub::TagManager.instance.public_collection?(uri) }
:public
elsif audience_searchable_by.include?(@account.followers_url)
:private
elsif audience_searchable_by.include?('kmyblue:Limited') || audience_searchable_by.include?('as:Limited')
:limited
else
elsif audience_searchable_by.include?(@account.uri) || audience_searchable_by.include?(@account.url)
:direct
else
:limited
end
end

Expand Down
16 changes: 8 additions & 8 deletions spec/lib/activitypub/activity/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -653,30 +653,30 @@ def activity_for_object(json)
end
end

context 'with direct when not specify' do
let(:searchable_by) { nil }
context 'with unintended value' do
let(:searchable_by) { 'ohagi' }

it 'create status' do
status = sender.statuses.first

expect(status).to_not be_nil
expect(status.searchability).to be_nil
expect(status.searchability).to eq 'limited'
end
end

context 'with limited' do
let(:searchable_by) { 'kmyblue:Limited' }
context 'with direct when not specify' do
let(:searchable_by) { nil }

it 'create status' do
status = sender.statuses.first

expect(status).to_not be_nil
expect(status.searchability).to eq 'limited'
expect(status.searchability).to be_nil
end
end

context 'with limited old spec' do
let(:searchable_by) { 'as:Limited' }
context 'with limited' do
let(:searchable_by) { 'kmyblue:Limited' }

it 'create status' do
status = sender.statuses.first
Expand Down
14 changes: 7 additions & 7 deletions spec/services/activitypub/process_account_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,19 @@
end
end

context 'when limited old spec' do
let(:searchable_by) { 'as:Limited' }
context 'when empty array' do
let(:searchable_by) { '' }

it 'searchability is limited' do
expect(subject.searchability).to eq 'limited'
it 'searchability is direct' do
expect(subject.searchability).to eq 'direct'
end
end

context 'when empty array' do
let(:searchable_by) { '' }
context 'when unintended value' do
let(:searchable_by) { 'ohagi' }

it 'searchability is direct' do
expect(subject.searchability).to eq 'direct'
expect(subject.searchability).to eq 'limited'
end
end

Expand Down

0 comments on commit 294acdf

Please sign in to comment.