handle followers

This commit is contained in:
Sebastian Jambor 2023-01-05 14:57:43 +01:00
parent 509b04c2a0
commit 60baa74a56
3 changed files with 50 additions and 2 deletions

View file

@ -19,7 +19,9 @@ class ActivityLogAudienceHelper
if match = activity_log_event.path.match(Regexp.new("https://#{domain}/users/([^/]*)/inbox"))
return [match.captures[0]]
elsif activity_log_event.path == "https://#{domain}/inbox"
return ['to', 'bto', 'cc', 'bcc'].map { |target| actors(activity_log_event.data[target]) }.flatten
return ['to', 'bto', 'cc', 'bcc']
.map { |target| actors(activity_log_event.data[target]) }
.flatten
end
return []
@ -41,10 +43,17 @@ class ActivityLogAudienceHelper
string_or_array.map do |string|
if match = string.match(Regexp.new("https://#{domain}/users/([^/]*)"))
match.captures[0]
elsif string.ends_with?("/followers")
Account
.joins(
"JOIN follows ON follows.account_id = accounts.id
JOIN accounts AS followed ON follows.target_account_id = followed.id
WHERE followed.followers_url = '#{string}'")
.map { |account| account.username }
else
nil
end
end.compact
end.flatten.compact
end
end
end

View file

@ -0,0 +1,25 @@
{
"timestamp":"2022-12-08T17:12:38Z",
"type": "inbound",
"path": "https://example.com/inbox",
"data": {
"@context": "https://www.w3.org/ns/activitystreams",
"actor": "https://other.org/users/bob/",
"id": "https://other.org/users/bob/statuses/109473290785654613/activity",
"object": {
"attributedTo": "https://other.org/users/bob/",
"content": "A post to selected audiences",
"id": "https://other.org/users/bob/statuses/109473290785654613",
"to": [
"https://www.w3.org/ns/activitystreams#Public",
"https://other.org/users/bob/followers"
],
"type": "Note"
},
"to": [
"https://www.w3.org/ns/activitystreams#Public",
"https://other.org/users/bob/followers"
],
"type": "Create"
}
}

View file

@ -59,6 +59,20 @@ RSpec.describe ActivityLogAudienceHelper do
'one-bcc'
])
end
it 'returns followers from to, bto, cc, bcc if sent to public inbox' do
Rails.configuration.x.web_domain = 'example.com'
inbound_event = activity_log_event_fixture('inbound-with-follower-recipients.json')
bob = Fabricate(:account, username: 'bob', followers_url: 'https://other.org/users/bob/followers')
Fabricate(:account, username: 'first_follower').follow!(bob)
Fabricate(:account, username: 'second_follower').follow!(bob)
expect(ActivityLogAudienceHelper.audience(inbound_event)).to match_array([
'first_follower',
'second_follower',
])
end
end
end
end