handle duplicates

This commit is contained in:
Sebastian Jambor 2023-01-05 15:02:09 +01:00
parent 60baa74a56
commit 14b89d1e71
3 changed files with 55 additions and 0 deletions

View file

@ -22,6 +22,7 @@ class ActivityLogAudienceHelper
return ['to', 'bto', 'cc', 'bcc']
.map { |target| actors(activity_log_event.data[target]) }
.flatten
.uniq
end
return []

View file

@ -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"
}
}

View file

@ -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