integrate audience helper

This commit is contained in:
Sebastian Jambor 2023-01-05 15:15:25 +01:00
parent 14b89d1e71
commit e13a05cb83
3 changed files with 12 additions and 13 deletions

View file

@ -76,7 +76,7 @@ class ActivityPub::InboxesController < ActivityPub::BaseController
end end
def process_payload def process_payload
event = ActivityLogEvent.new('inbound', request.path, Oj.load(body, mode: :strict)) event = ActivityLogEvent.new('inbound', "https://#{Rails.configuration.x.web_domain}#{request.path}", Oj.load(body, mode: :strict))
@activity_log_publisher.publish(event) @activity_log_publisher.publish(event)

View file

@ -9,26 +9,24 @@ class ActivityLogAudienceHelper
actor = activity_log_event.data['actor'] actor = activity_log_event.data['actor']
if actor and match = actor.match(Regexp.new("https://#{domain}/users/([^/]*)")) if actor and match = actor.match(Regexp.new("https://#{domain}/users/([^/]*)"))
return [match.captures[0]] [match.captures[0]]
else else
return [] []
end end
end elsif activity_log_event.type == 'inbound'
if activity_log_event.type == 'inbound'
if match = activity_log_event.path.match(Regexp.new("https://#{domain}/users/([^/]*)/inbox")) if match = activity_log_event.path.match(Regexp.new("https://#{domain}/users/([^/]*)/inbox"))
return [match.captures[0]] [match.captures[0]]
elsif activity_log_event.path == "https://#{domain}/inbox" elsif activity_log_event.path == "https://#{domain}/inbox"
return ['to', 'bto', 'cc', 'bcc'] ['to', 'bto', 'cc', 'bcc']
.map { |target| actors(activity_log_event.data[target]) } .map { |target| actors(activity_log_event.data[target]) }
.flatten .flatten
.uniq .uniq
else
[]
end end
else
return [] []
end end
return []
end end
private private

View file

@ -10,7 +10,8 @@ class ActivityLogSubscriber
json = Oj.load(message, mode: :strict) json = Oj.load(message, mode: :strict)
event = ActivityLogEvent.new(json['type'], json['path'], json['data']) event = ActivityLogEvent.new(json['type'], json['path'], json['data'])
ActivityLogger.log('admin', event) ActivityLogAudienceHelper.audience(event)
.each { |username| ActivityLogger.log(username, event) }
end end
end end
end end