Fix addressing of remote groups' followers (#16700)

Fixes #16699
master
Claire 3 years ago committed by GitHub
parent 7c7e78d807
commit 12cd097e7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      app/lib/activitypub/tag_manager.rb
  2. 8
      spec/lib/activitypub/tag_manager_spec.rb

@ -64,6 +64,10 @@ class ActivityPub::TagManager
account_status_replies_url(target.account, target, page_params) account_status_replies_url(target.account, target, page_params)
end end
def followers_uri_for(target)
target.local? ? account_followers_url(target) : target.followers_url.presence
end
# Primary audience of a status # Primary audience of a status
# Public statuses go out to primarily the public collection # Public statuses go out to primarily the public collection
# Unlisted and private statuses go out primarily to the followers collection # Unlisted and private statuses go out primarily to the followers collection
@ -80,17 +84,17 @@ class ActivityPub::TagManager
account_ids = status.active_mentions.pluck(:account_id) account_ids = status.active_mentions.pluck(:account_id)
to = status.account.followers.where(id: account_ids).each_with_object([]) do |account, result| to = status.account.followers.where(id: account_ids).each_with_object([]) do |account, result|
result << uri_for(account) result << uri_for(account)
result << account_followers_url(account) if account.group? result << followers_uri_for(account) if account.group?
end end
to.concat(FollowRequest.where(target_account_id: status.account_id, account_id: account_ids).each_with_object([]) do |request, result| 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 << uri_for(request.account)
result << account_followers_url(request.account) if request.account.group? result << followers_uri_for(request.account) if request.account.group?
end) end).compact
else else
status.active_mentions.each_with_object([]) do |mention, result| status.active_mentions.each_with_object([]) do |mention, result|
result << uri_for(mention.account) result << uri_for(mention.account)
result << account_followers_url(mention.account) if mention.account.group? result << followers_uri_for(mention.account) if mention.account.group?
end end.compact
end end
end end
end end
@ -118,17 +122,17 @@ class ActivityPub::TagManager
account_ids = status.active_mentions.pluck(:account_id) account_ids = status.active_mentions.pluck(:account_id)
cc.concat(status.account.followers.where(id: account_ids).each_with_object([]) do |account, result| cc.concat(status.account.followers.where(id: account_ids).each_with_object([]) do |account, result|
result << uri_for(account) result << uri_for(account)
result << account_followers_url(account) if account.group? result << followers_uri_for(account) if account.group?
end) end.compact)
cc.concat(FollowRequest.where(target_account_id: status.account_id, account_id: account_ids).each_with_object([]) do |request, result| 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 << uri_for(request.account)
result << account_followers_url(request.account) if request.account.group? result << followers_uri_for(request.account) if request.account.group?
end) end.compact)
else else
cc.concat(status.active_mentions.each_with_object([]) do |mention, result| cc.concat(status.active_mentions.each_with_object([]) do |mention, result|
result << uri_for(mention.account) result << uri_for(mention.account)
result << account_followers_url(mention.account) if mention.account.group? result << followers_uri_for(mention.account) if mention.account.group?
end) end.compact)
end end
end end

@ -42,6 +42,14 @@ RSpec.describe ActivityPub::TagManager do
expect(subject.to(status)).to eq [subject.uri_for(mentioned)] expect(subject.to(status)).to eq [subject.uri_for(mentioned)]
end 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 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') bob = Fabricate(:account, username: 'bob')
alice = Fabricate(:account, username: 'alice') alice = Fabricate(:account, username: 'alice')

Loading…
Cancel
Save