Skip to content

Commit ff38cb1

Browse files
ClearlyClairekadoshita
authored andcommitted
Fix addressing of remote groups' followers (mastodon#16700)
Fixes mastodon#16699
1 parent 3cafb51 commit ff38cb1

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

app/lib/activitypub/tag_manager.rb

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ def replies_uri_for(target, page_params = nil)
6464
account_status_replies_url(target.account, target, page_params)
6565
end
6666

67+
def followers_uri_for(target)
68+
target.local? ? account_followers_url(target) : target.followers_url.presence
69+
end
70+
6771
# Primary audience of a status
6872
# Public statuses go out to primarily the public collection
6973
# Unlisted and private statuses go out primarily to the followers collection
@@ -80,17 +84,17 @@ def to(status)
8084
account_ids = status.active_mentions.pluck(:account_id)
8185
to = status.account.followers.where(id: account_ids).each_with_object([]) do |account, result|
8286
result << uri_for(account)
83-
result << account_followers_url(account) if account.group?
87+
result << followers_uri_for(account) if account.group?
8488
end
8589
to.concat(FollowRequest.where(target_account_id: status.account_id, account_id: account_ids).each_with_object([]) do |request, result|
8690
result << uri_for(request.account)
87-
result << account_followers_url(request.account) if request.account.group?
88-
end)
91+
result << followers_uri_for(request.account) if request.account.group?
92+
end).compact
8993
else
9094
status.active_mentions.each_with_object([]) do |mention, result|
9195
result << uri_for(mention.account)
92-
result << account_followers_url(mention.account) if mention.account.group?
93-
end
96+
result << followers_uri_for(mention.account) if mention.account.group?
97+
end.compact
9498
end
9599
end
96100
end
@@ -118,17 +122,17 @@ def cc(status)
118122
account_ids = status.active_mentions.pluck(:account_id)
119123
cc.concat(status.account.followers.where(id: account_ids).each_with_object([]) do |account, result|
120124
result << uri_for(account)
121-
result << account_followers_url(account) if account.group?
122-
end)
125+
result << followers_uri_for(account) if account.group?
126+
end.compact)
123127
cc.concat(FollowRequest.where(target_account_id: status.account_id, account_id: account_ids).each_with_object([]) do |request, result|
124128
result << uri_for(request.account)
125-
result << account_followers_url(request.account) if request.account.group?
126-
end)
129+
result << followers_uri_for(request.account) if request.account.group?
130+
end.compact)
127131
else
128132
cc.concat(status.active_mentions.each_with_object([]) do |mention, result|
129133
result << uri_for(mention.account)
130-
result << account_followers_url(mention.account) if mention.account.group?
131-
end)
134+
result << followers_uri_for(mention.account) if mention.account.group?
135+
end.compact)
132136
end
133137
end
134138

spec/lib/activitypub/tag_manager_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
expect(subject.to(status)).to eq [subject.uri_for(mentioned)]
4343
end
4444

45+
it "returns URIs of mentioned group's followers for direct statuses to groups" do
46+
status = Fabricate(:status, visibility: :direct)
47+
mentioned = Fabricate(:account, domain: 'remote.org', uri: 'https://remote.org/group', followers_url: 'https://remote.org/group/followers', actor_type: 'Group')
48+
status.mentions.create(account: mentioned)
49+
expect(subject.to(status)).to include(subject.uri_for(mentioned))
50+
expect(subject.to(status)).to include(subject.followers_uri_for(mentioned))
51+
end
52+
4553
it "returns URIs of mentions for direct silenced author's status only if they are followers or requesting to be" do
4654
bob = Fabricate(:account, username: 'bob')
4755
alice = Fabricate(:account, username: 'alice')

0 commit comments

Comments
 (0)