diff --git a/app/lib/activity_log_audience_helper.rb b/app/lib/activity_log_audience_helper.rb index f0af297f7..f9a359310 100644 --- a/app/lib/activity_log_audience_helper.rb +++ b/app/lib/activity_log_audience_helper.rb @@ -22,6 +22,7 @@ class ActivityLogAudienceHelper return ['to', 'bto', 'cc', 'bcc'] .map { |target| actors(activity_log_event.data[target]) } .flatten + .uniq end return [] diff --git a/spec/fixtures/activity_log_events/inbound-with-duplicate-recipients.json b/spec/fixtures/activity_log_events/inbound-with-duplicate-recipients.json new file mode 100644 index 000000000..f9080cd3b --- /dev/null +++ b/spec/fixtures/activity_log_events/inbound-with-duplicate-recipients.json @@ -0,0 +1,43 @@ +{ + "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://example.com/users/first-to", + "https://example.com/users/first-to", + "https://example.com/users/second-to" + ], + "bto": "https://example.com/users/first-to", + "cc": [ + "https://example.com/users/second-to" + ], + "bcc": [ + "https://example.com/users/first-to" + ], + "type": "Note" + }, + "to": [ + "https://www.w3.org/ns/activitystreams#Public", + "https://example.com/users/first-to", + "https://example.com/users/first-to", + "https://example.com/users/second-to" + ], + "bto": "https://example.com/users/first-to", + "cc": [ + "https://example.com/users/second-to" + ], + "bcc": [ + "https://example.com/users/first-to" + ], + "type": "Create" + } +} diff --git a/spec/lib/activity_log_audience_helper_spec.rb b/spec/lib/activity_log_audience_helper_spec.rb index 971e68d96..5f72f852b 100644 --- a/spec/lib/activity_log_audience_helper_spec.rb +++ b/spec/lib/activity_log_audience_helper_spec.rb @@ -73,6 +73,17 @@ RSpec.describe ActivityLogAudienceHelper do 'second_follower', ]) end + + it 'removes duplicates from audience' do + Rails.configuration.x.web_domain = 'example.com' + inbound_event = activity_log_event_fixture('inbound-with-duplicate-recipients.json') + + expect(ActivityLogAudienceHelper.audience(inbound_event)).to match_array([ + 'first-to', + 'second-to' + ]) + end + end end end