Skip to content

Commit

Permalink
Change: サークルの送り先アカウント指定方法をaccount_username(Fedibirdと同様)に変更 (#283)
Browse files Browse the repository at this point in the history
* Change: サークルの送り先アカウント指定方法を`account_username`(Fedibirdと同様)に変更

* Test: テストを追加

* Maybe Fix: Fedibirdで自分限定と認識される問題
  • Loading branch information
kmycode authored Nov 16, 2023
1 parent 7742f44 commit 0f01a71
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
5 changes: 1 addition & 4 deletions app/lib/activitypub/tag_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ def to(status)
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

Expand Down
6 changes: 6 additions & 0 deletions app/lib/status_reach_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ def inboxes_for_friend
(reached_account_inboxes_for_friend + followers_inboxes_for_friend + friend_inboxes).uniq
end

def inboxes_for_limited
DeliveryFailureTracker.without_unavailable(
@status.mentioned_accounts.where.not(domain: nil).pluck(:inbox_url).compact.uniq
)
end

def all_inboxes
(inboxes + inboxes_for_misskey + inboxes_for_friend).uniq
end
Expand Down
16 changes: 15 additions & 1 deletion app/workers/activitypub/distribution_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ def perform(status_id)
@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
Expand All @@ -26,6 +36,10 @@ def inboxes_for_friend
@inboxes_for_friend ||= status_reach_finder.inboxes_for_friend
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
Expand Down
28 changes: 27 additions & 1 deletion spec/workers/activitypub/distribution_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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
Expand All @@ -25,6 +25,18 @@
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]]) do
subject.perform(status.id)
end
end
end

context 'with private status' do
before do
status.update(visibility: :private)
Expand All @@ -37,6 +49,20 @@
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]]) do
subject.perform(status.id)
end
end
end

context 'with direct status' do
let(:mentioned_account) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://foo.bar/inbox', domain: 'foo.bar') }

Expand Down

0 comments on commit 0f01a71

Please sign in to comment.