extending functionality of audience helper

This commit is contained in:
Sebastian Jambor 2023-01-04 19:35:24 +01:00
parent b0a0f57e82
commit c8ea90f6f1
3 changed files with 52 additions and 3 deletions

View file

@ -3,10 +3,12 @@
class ActivityLogAudienceHelper
def self.audience(activity_log_event)
domain = Rails.configuration.x.local_domain
if activity_log_event.type == 'outbound'
actor = activity_log_event.data['actor']
if actor and match = actor.match(Regexp.new("https://#{Rails.configuration.x.local_domain}/users/(.*)"))
if actor and match = actor.match(Regexp.new("https://#{domain}/users/(.*)"))
return [match.captures[0]]
else
return []
@ -14,13 +16,15 @@ class ActivityLogAudienceHelper
end
if activity_log_event.type == 'inbound'
if match = activity_log_event.path.match(Regexp.new("https://#{Rails.configuration.x.local_domain}/users/(.*)/inbox"))
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"
end
return []
end
return ['admin']
return []
end
end

View file

@ -0,0 +1,38 @@
{
"@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/second-to",
"https://other.org/users/other-instance"
],
"bto": "https://example.com/users/single-bto",
"cc": [
"https://example.com/users/one-cc"
],
"bcc": [
"https://example.com/users/one-bcc"
],
"type": "Note"
},
"to": [
"https://www.w3.org/ns/activitystreams#Public",
"https://example.com/users/first-to",
"https://example.com/users/second-to",
"https://other.org/users/other-instance"
],
"bto": "https://example.com/users/single-bto",
"cc": [
"https://example.com/users/one-cc"
],
"bcc": [
"https://example.com/users/one-bcc"
],
"type": "Create"
}

View file

@ -46,6 +46,13 @@ RSpec.describe ActivityLogAudienceHelper do
expect(ActivityLogAudienceHelper.audience(inbound_event)).to eq ['bob']
end
it 'returns direct audience from to, bto, cc, bcc if sent to public inbox' do
Rails.configuration.x.local_domain = 'example.com'
inbound_event = activity_log_event_fixture('inbound-with-multiple-recipients.json')
expect(ActivityLogAudienceHelper.audience(inbound_event)).to match_array(['first-to', 'second-to', 'single-bto', 'one-cc', 'one-bcc'])
end
end
end
end