From 8383288219a5a0da41e581a727cfb70a742e3760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KMY=EF=BC=88=E9=9B=AA=E3=81=82=E3=81=99=E3=81=8B=EF=BC=89?= Date: Tue, 28 Nov 2023 12:54:03 +0900 Subject: [PATCH] =?UTF-8?q?Change:=20=E3=82=B5=E3=83=BC=E3=82=AF=E3=83=AB?= =?UTF-8?q?=E3=81=AE=E9=80=81=E3=82=8A=E5=85=88=E3=82=A2=E3=82=AB=E3=82=A6?= =?UTF-8?q?=E3=83=B3=E3=83=88=E6=8C=87=E5=AE=9A=E6=96=B9=E6=B3=95=E3=82=92?= =?UTF-8?q?`account=5Fusername`=EF=BC=88Fedibird=E3=81=A8=E5=90=8C?= =?UTF-8?q?=E6=A7=98=EF=BC=89=E3=81=AB=E5=A4=89=E6=9B=B4=20(#283)=20(LTS)?= =?UTF-8?q?=20(#308)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Change: サークルの送り先アカウント指定方法を`account_username`(Fedibirdと同様)に変更 (#283) * Change: サークルの送り先アカウント指定方法を`account_username`(Fedibirdと同様)に変更 * Test: テストを追加 * Maybe Fix: Fedibirdで自分限定と認識される問題 * Fix test --- app/lib/activitypub/tag_manager.rb | 5 +--- app/lib/status_reach_finder.rb | 6 +++++ .../activitypub/distribution_worker.rb | 16 +++++++++++- .../activitypub/distribution_worker_spec.rb | 26 ++++++++++++++++++- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/app/lib/activitypub/tag_manager.rb b/app/lib/activitypub/tag_manager.rb index f9b67867ef..52f7ed32ab 100644 --- a/app/lib/activitypub/tag_manager.rb +++ b/app/lib/activitypub/tag_manager.rb @@ -119,10 +119,7 @@ class ActivityPub::TagManager end.compact end when 'limited' - status.mentions.each_with_object([]) do |mention, result| - result << uri_for(mention.account) - result << followers_uri_for(mention.account) if mention.account.group? - end.compact + ['kmyblue:Limited'] # to avoid Fedibird personal visibility end end diff --git a/app/lib/status_reach_finder.rb b/app/lib/status_reach_finder.rb index 8639a30a9f..c7069c7dac 100644 --- a/app/lib/status_reach_finder.rb +++ b/app/lib/status_reach_finder.rb @@ -21,6 +21,12 @@ class StatusReachFinder end end + def inboxes_for_limited + DeliveryFailureTracker.without_unavailable( + @status.mentioned_accounts.where.not(domain: nil).pluck(:inbox_url).compact.uniq + ) + end + private def reached_account_inboxes diff --git a/app/workers/activitypub/distribution_worker.rb b/app/workers/activitypub/distribution_worker.rb index 34b6f6e32f..57ee1fbc0a 100644 --- a/app/workers/activitypub/distribution_worker.rb +++ b/app/workers/activitypub/distribution_worker.rb @@ -7,13 +7,23 @@ class ActivityPub::DistributionWorker < ActivityPub::RawDistributionWorker @status = Status.find(status_id) @account = @status.account - distribute! + if @status.limited_visibility? + distribute_limited! + else + distribute! + end rescue ActiveRecord::RecordNotFound true end protected + def distribute_limited! + ActivityPub::DeliveryWorker.push_bulk(inboxes_for_limited, limit: 1_000) do |inbox_url| + [payload, @account.id, inbox_url, options] + end + end + def inboxes @inboxes ||= status_reach_finder.inboxes end @@ -22,6 +32,10 @@ class ActivityPub::DistributionWorker < ActivityPub::RawDistributionWorker @inboxes_for_misskey ||= status_reach_finder.inboxes_for_misskey end + def inboxes_for_limited + @inboxes_for_limited ||= status_reach_finder.inboxes_for_limited + end + def status_reach_finder @status_reach_finder ||= StatusReachFinder.new(@status) end diff --git a/spec/workers/activitypub/distribution_worker_spec.rb b/spec/workers/activitypub/distribution_worker_spec.rb index d8803f6b8a..aaf4dbfcce 100644 --- a/spec/workers/activitypub/distribution_worker_spec.rb +++ b/spec/workers/activitypub/distribution_worker_spec.rb @@ -6,7 +6,7 @@ describe ActivityPub::DistributionWorker do subject { described_class.new } let(:status) { Fabricate(:status) } - let(:follower) { Fabricate(:account, protocol: :activitypub, inbox_url: 'http://example.com', domain: 'example.com') } + let(:follower) { Fabricate(:account, protocol: :activitypub, shared_inbox_url: 'http://example.com', inbox_url: 'http://example.com/follower/inbox', domain: 'example.com') } describe '#perform' do before do @@ -24,6 +24,17 @@ describe ActivityPub::DistributionWorker do end end + context 'with unlisted status' do + before do + status.update(visibility: :unlisted) + end + + it 'delivers to followers' do + expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com', anything]]) + subject.perform(status.id) + end + end + context 'with private status' do before do status.update(visibility: :private) @@ -35,6 +46,19 @@ describe ActivityPub::DistributionWorker do end end + context 'with limited status' do + before do + status.update(visibility: :limited) + status.capability_tokens.create! + status.mentions.create!(account: follower, silent: true) + end + + it 'delivers to followers' do + expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com/follower/inbox', anything]]) + subject.perform(status.id) + end + end + context 'with direct status' do let(:mentioned_account) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://foo.bar/inbox', domain: 'foo.bar') }