add sender to activity log json
This commit is contained in:
parent
db42b86def
commit
57f7eb4cd8
12 changed files with 25 additions and 19 deletions
|
@ -76,7 +76,13 @@ class ActivityPub::InboxesController < ActivityPub::BaseController
|
|||
end
|
||||
|
||||
def process_payload
|
||||
event = ActivityLogEvent.new('inbound', "https://#{Rails.configuration.x.web_domain}#{request.path}", Oj.load(body, mode: :strict))
|
||||
raw_signature = request.headers['Signature']
|
||||
tree = SignatureParamsParser.new.parse(raw_signature)
|
||||
signature_params = SignatureParamsTransformer.new.apply(tree)
|
||||
|
||||
sender = actor_from_key_id(signature_params['keyId'])
|
||||
|
||||
event = ActivityLogEvent.new('inbound', sender.uri, "https://#{Rails.configuration.x.web_domain}#{request.path}", Oj.load(body, mode: :strict))
|
||||
|
||||
@activity_log_publisher.publish(event)
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@ class ActivityLogAudienceHelper
|
|||
domain = Rails.configuration.x.web_domain
|
||||
|
||||
if activity_log_event.type == 'outbound'
|
||||
actor = activity_log_event.data['actor']
|
||||
sender = activity_log_event.sender
|
||||
|
||||
if actor and match = actor.match(Regexp.new("https://#{domain}/users/([^/]*)"))
|
||||
if sender and match = sender.match(Regexp.new("https://#{domain}/users/([^/]*)"))
|
||||
[match.captures[0]]
|
||||
else
|
||||
[]
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ActivityLogEvent
|
||||
attr_accessor :type, :path, :data, :timestamp
|
||||
attr_accessor :type, :sender, :path, :data, :timestamp
|
||||
|
||||
def self.from_json_string(json_string)
|
||||
json = Oj.load(json_string, mode: :strict)
|
||||
ActivityLogEvent.new(json['type'], json['path'], json['data'])
|
||||
ActivityLogEvent.new(json['type'], json['sender'], json['path'], json['data'])
|
||||
end
|
||||
|
||||
|
||||
def initialize(type, path, data, timestamp = Time.now.utc.iso8601)
|
||||
def initialize(type, sender, path, data, timestamp = Time.now.utc.iso8601)
|
||||
@type = type
|
||||
@sender = sender
|
||||
@path = path
|
||||
@data = data
|
||||
@timestamp = timestamp
|
||||
|
|
|
@ -28,7 +28,7 @@ class ActivityLogger
|
|||
|
||||
Thread.new {
|
||||
while true
|
||||
event = ActivityLogEvent.new('keep-alive', nil, nil)
|
||||
event = ActivityLogEvent.new('keep-alive', nil, nil, nil)
|
||||
@@loggers.each_key do |key|
|
||||
ActivityLogger.log(key, event)
|
||||
end
|
||||
|
|
|
@ -29,10 +29,6 @@ class ActivityPub::DeliveryWorker
|
|||
def perform(json, source_account_id, inbox_url, options = {})
|
||||
return unless DeliveryFailureTracker.available?(inbox_url)
|
||||
|
||||
event = ActivityLogEvent.new('outbound', inbox_url, Oj.load(json, mode: :strict))
|
||||
|
||||
@activity_log_publisher.publish(event)
|
||||
|
||||
@options = options.with_indifferent_access
|
||||
@json = json
|
||||
@source_account = Account.find(source_account_id)
|
||||
|
@ -40,6 +36,11 @@ class ActivityPub::DeliveryWorker
|
|||
@host = Addressable::URI.parse(inbox_url).normalized_site
|
||||
@performed = false
|
||||
|
||||
event = ActivityLogEvent.new('outbound', "https://#{Rails.configuration.x.web_domain}/users/#{@source_account.username}", inbox_url, Oj.load(json, mode: :strict))
|
||||
|
||||
@activity_log_publisher.publish(event)
|
||||
|
||||
|
||||
perform_request
|
||||
ensure
|
||||
if @inbox_url.present?
|
||||
|
|
|
@ -7,8 +7,7 @@ class ActivityLogSubscriber
|
|||
|
||||
redis.subscribe('activity_log') do |on|
|
||||
on.message do |channel, message|
|
||||
json = Oj.load(message, mode: :strict)
|
||||
event = ActivityLogEvent.new(json['type'], json['path'], json['data'])
|
||||
event = ActivityLogEvent.from_json_string(message)
|
||||
|
||||
ActivityLogAudienceHelper.audience(event)
|
||||
.each { |username| ActivityLogger.log(username, event) }
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"timestamp":"2022-12-08T17:12:38Z",
|
||||
"sender": "https://other.org/users/alice",
|
||||
"type": "inbound",
|
||||
"path": "https://example.com/users/bob/inbox",
|
||||
"data": {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"timestamp":"2022-12-08T17:12:38Z",
|
||||
"sender": "https://other.org/users/bob/",
|
||||
"type": "inbound",
|
||||
"path": "https://example.com/inbox",
|
||||
"data": {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"timestamp":"2022-12-08T17:12:38Z",
|
||||
"sender": "https://other.org/users/bob/",
|
||||
"type": "inbound",
|
||||
"path": "https://example.com/inbox",
|
||||
"data": {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"timestamp":"2022-12-08T17:12:38Z",
|
||||
"sender": "https://other.org/users/bob/",
|
||||
"type": "inbound",
|
||||
"path": "https://example.com/inbox",
|
||||
"data": {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"timestamp":"2022-12-08T17:12:38Z",
|
||||
"sender": "https://example.com/users/alice",
|
||||
"type": "outbound",
|
||||
"path": "https://other.org/users/bob/inbox",
|
||||
"data": {
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
require 'json'
|
||||
require 'rails_helper'
|
||||
|
||||
def activity_log_event_fixture(name)
|
||||
json_string = File.read(Rails.root.join('spec', 'fixtures', 'activity_log_events', name))
|
||||
|
||||
ActivityLogEvent.from_json_string(json_string)
|
||||
end
|
||||
|
||||
RSpec.describe ActivityLogger do
|
||||
|
||||
after(:each) do
|
||||
|
|
Loading…
Reference in a new issue