From 91a2dc81c43d08a26ae4689e1e7a67c3bb245ab3 Mon Sep 17 00:00:00 2001 From: KMY Date: Tue, 10 Sep 2024 06:51:26 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Fix:=20LD=20Signatures=E3=81=A7=E7=BD=B2?= =?UTF-8?q?=E5=90=8D=E3=81=95=E3=82=8C=E3=81=9F=E6=8A=95=E7=A8=BF=E3=81=AE?= =?UTF-8?q?=E6=A4=9C=E7=B4=A2=E8=A8=B1=E5=8F=AF=EF=BC=88=E6=A4=9C=E7=B4=A2?= =?UTF-8?q?=E7=AF=84=E5=9B=B2=EF=BC=89=E3=81=8C=E6=94=B9=E7=AB=84=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/activitypub/parser/status_parser.rb | 8 ++++---- app/lib/activitypub/tag_manager.rb | 2 +- app/services/activitypub/process_account_service.rb | 2 +- spec/lib/activitypub/activity/create_spec.rb | 13 ++++++++++++- spec/lib/activitypub/tag_manager_spec.rb | 2 +- .../serializers/activitypub/note_serializer_spec.rb | 8 ++++++++ .../activitypub/process_account_service_spec.rb | 10 +++++++++- 7 files changed, 36 insertions(+), 9 deletions(-) diff --git a/app/lib/activitypub/parser/status_parser.rb b/app/lib/activitypub/parser/status_parser.rb index a2ae658874..cc9788e964 100644 --- a/app/lib/activitypub/parser/status_parser.rb +++ b/app/lib/activitypub/parser/status_parser.rb @@ -203,9 +203,9 @@ class ActivityPub::Parser::StatusParser end def searchability_from_audience - if audience_searchable_by.nil? - nil - elsif audience_searchable_by.any? { |uri| ActivityPub::TagManager.instance.public_collection?(uri) } + return nil if audience_searchable_by.blank? + + 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 @@ -213,7 +213,7 @@ class ActivityPub::Parser::StatusParser :public_unlisted elsif audience_searchable_by.include?(@account.followers_url) :private - else + elsif audience_searchable_by.include?(@account.uri) || audience_searchable_by.include?(@account.url) :direct end end diff --git a/app/lib/activitypub/tag_manager.rb b/app/lib/activitypub/tag_manager.rb index 84e5ea547d..6fe5db3769 100644 --- a/app/lib/activitypub/tag_manager.rb +++ b/app/lib/activitypub/tag_manager.rb @@ -252,7 +252,7 @@ class ActivityPub::TagManager when 'limited' ['as:Limited', 'kmyblue:Limited'] else - [] + [account_url(status.account)] end searchable_by.concat(mentions_uris(status)).compact diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index 474fad59d5..1440e3d8ae 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -282,7 +282,7 @@ class ActivityPub::ProcessAccountService < BaseService end def searchability_from_audience - if audience_searchable_by.nil? + if audience_searchable_by.blank? bio = searchability_from_bio return bio unless bio.nil? diff --git a/spec/lib/activitypub/activity/create_spec.rb b/spec/lib/activitypub/activity/create_spec.rb index a84eb887a1..03793c4475 100644 --- a/spec/lib/activitypub/activity/create_spec.rb +++ b/spec/lib/activitypub/activity/create_spec.rb @@ -632,7 +632,7 @@ RSpec.describe ActivityPub::Activity::Create do end context 'with direct' do - let(:searchable_by) { '' } + let(:searchable_by) { 'https://example.com/actor' } it 'create status' do status = sender.statuses.first @@ -642,6 +642,17 @@ RSpec.describe ActivityPub::Activity::Create do end end + context 'with empty array' do + let(:searchable_by) { '' } + + it 'create status' do + status = sender.statuses.first + + expect(status).to_not be_nil + expect(status.searchability).to be_nil + end + end + context 'with direct when not specify' do let(:searchable_by) { nil } diff --git a/spec/lib/activitypub/tag_manager_spec.rb b/spec/lib/activitypub/tag_manager_spec.rb index 0d9c23cb5e..2bc7820542 100644 --- a/spec/lib/activitypub/tag_manager_spec.rb +++ b/spec/lib/activitypub/tag_manager_spec.rb @@ -210,7 +210,7 @@ RSpec.describe ActivityPub::TagManager do it 'returns empty array for direct status' do status = Fabricate(:status, searchability: :direct) - expect(subject.searchable_by(status)).to eq [] + expect(subject.searchable_by(status)).to eq ["https://cb6e6126.ngrok.io/users/#{status.account.username}"] end it 'returns as:Limited array for limited status' do diff --git a/spec/serializers/activitypub/note_serializer_spec.rb b/spec/serializers/activitypub/note_serializer_spec.rb index e7f553ca57..963dd6afb5 100644 --- a/spec/serializers/activitypub/note_serializer_spec.rb +++ b/spec/serializers/activitypub/note_serializer_spec.rb @@ -81,6 +81,14 @@ RSpec.describe ActivityPub::NoteSerializer do end end + context 'when direct searchability' do + let(:searchability) { :direct } + + it 'send as direct searchability' do + expect(subject['searchableBy']).to include "https://cb6e6126.ngrok.io/users/#{account.username}" + end + end + context 'when has a reference' do let(:referred) { Fabricate(:status) } diff --git a/spec/services/activitypub/process_account_service_spec.rb b/spec/services/activitypub/process_account_service_spec.rb index e399daf2a7..5febc49e51 100644 --- a/spec/services/activitypub/process_account_service_spec.rb +++ b/spec/services/activitypub/process_account_service_spec.rb @@ -150,7 +150,7 @@ RSpec.describe ActivityPub::ProcessAccountService do end context 'when direct' do - let(:searchable_by) { '' } + let(:searchable_by) { 'https://foo.test' } it 'searchability is direct' do expect(subject.searchability).to eq 'direct' @@ -173,6 +173,14 @@ RSpec.describe ActivityPub::ProcessAccountService do end end + context 'when empty array' do + let(:searchable_by) { '' } + + it 'searchability is direct' do + expect(subject.searchability).to eq 'direct' + end + end + context 'when default value' do let(:searchable_by) { nil } From a94959a35f90a65fcec455cf74675a5cc4495c69 Mon Sep 17 00:00:00 2001 From: KMY Date: Tue, 10 Sep 2024 07:25:17 +0900 Subject: [PATCH 2/2] Fix account searchability --- app/lib/activitypub/tag_manager.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/activitypub/tag_manager.rb b/app/lib/activitypub/tag_manager.rb index 6fe5db3769..53f0f0c693 100644 --- a/app/lib/activitypub/tag_manager.rb +++ b/app/lib/activitypub/tag_manager.rb @@ -273,7 +273,7 @@ class ActivityPub::TagManager when 'limited' ['as:Limited', 'kmyblue:Limited'] else - [] + [account_url(account)] end end