Skip to content

Commit

Permalink
Fix addressing of remote groups' followers (mastodon#16700)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and kadoshita committed Nov 7, 2021
1 parent 6479f4b commit 11ec593
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
26 changes: 15 additions & 11 deletions app/lib/activitypub/tag_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def replies_uri_for(target, page_params = nil)
account_status_replies_url(target.account, target, page_params)
end

def followers_uri_for(target)
target.local? ? account_followers_url(target) : target.followers_url.presence
end

# Primary audience of a status
# Public statuses go out to primarily the public collection
# Unlisted and private statuses go out primarily to the followers collection
Expand All @@ -80,17 +84,17 @@ def to(status)
account_ids = status.active_mentions.pluck(:account_id)
to = status.account.followers.where(id: account_ids).each_with_object([]) do |account, result|
result << uri_for(account)
result << account_followers_url(account) if account.group?
result << followers_uri_for(account) if account.group?
end
to.concat(FollowRequest.where(target_account_id: status.account_id, account_id: account_ids).each_with_object([]) do |request, result|
result << uri_for(request.account)
result << account_followers_url(request.account) if request.account.group?
end)
result << followers_uri_for(request.account) if request.account.group?
end).compact
else
status.active_mentions.each_with_object([]) do |mention, result|
result << uri_for(mention.account)
result << account_followers_url(mention.account) if mention.account.group?
end
result << followers_uri_for(mention.account) if mention.account.group?
end.compact
end
end
end
Expand Down Expand Up @@ -118,17 +122,17 @@ def cc(status)
account_ids = status.active_mentions.pluck(:account_id)
cc.concat(status.account.followers.where(id: account_ids).each_with_object([]) do |account, result|
result << uri_for(account)
result << account_followers_url(account) if account.group?
end)
result << followers_uri_for(account) if account.group?
end.compact)
cc.concat(FollowRequest.where(target_account_id: status.account_id, account_id: account_ids).each_with_object([]) do |request, result|
result << uri_for(request.account)
result << account_followers_url(request.account) if request.account.group?
end)
result << followers_uri_for(request.account) if request.account.group?
end.compact)
else
cc.concat(status.active_mentions.each_with_object([]) do |mention, result|
result << uri_for(mention.account)
result << account_followers_url(mention.account) if mention.account.group?
end)
result << followers_uri_for(mention.account) if mention.account.group?
end.compact)
end
end

Expand Down
8 changes: 8 additions & 0 deletions spec/lib/activitypub/tag_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
expect(subject.to(status)).to eq [subject.uri_for(mentioned)]
end

it "returns URIs of mentioned group's followers for direct statuses to groups" do
status = Fabricate(:status, visibility: :direct)
mentioned = Fabricate(:account, domain: 'remote.org', uri: 'https://remote.org/group', followers_url: 'https://remote.org/group/followers', actor_type: 'Group')
status.mentions.create(account: mentioned)
expect(subject.to(status)).to include(subject.uri_for(mentioned))
expect(subject.to(status)).to include(subject.followers_uri_for(mentioned))
end

it "returns URIs of mentions for direct silenced author's status only if they are followers or requesting to be" do
bob = Fabricate(:account, username: 'bob')
alice = Fabricate(:account, username: 'alice')
Expand Down

0 comments on commit 11ec593

Please sign in to comment.