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
|
end
|
||||||
|
|
||||||
def process_payload
|
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)
|
@activity_log_publisher.publish(event)
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@ class ActivityLogAudienceHelper
|
||||||
domain = Rails.configuration.x.web_domain
|
domain = Rails.configuration.x.web_domain
|
||||||
|
|
||||||
if activity_log_event.type == 'outbound'
|
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]]
|
[match.captures[0]]
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ActivityLogEvent
|
class ActivityLogEvent
|
||||||
attr_accessor :type, :path, :data, :timestamp
|
attr_accessor :type, :sender, :path, :data, :timestamp
|
||||||
|
|
||||||
def self.from_json_string(json_string)
|
def self.from_json_string(json_string)
|
||||||
json = Oj.load(json_string, mode: :strict)
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
def initialize(type, path, data, timestamp = Time.now.utc.iso8601)
|
def initialize(type, sender, path, data, timestamp = Time.now.utc.iso8601)
|
||||||
@type = type
|
@type = type
|
||||||
|
@sender = sender
|
||||||
@path = path
|
@path = path
|
||||||
@data = data
|
@data = data
|
||||||
@timestamp = timestamp
|
@timestamp = timestamp
|
||||||
|
|
|
@ -28,7 +28,7 @@ class ActivityLogger
|
||||||
|
|
||||||
Thread.new {
|
Thread.new {
|
||||||
while true
|
while true
|
||||||
event = ActivityLogEvent.new('keep-alive', nil, nil)
|
event = ActivityLogEvent.new('keep-alive', nil, nil, nil)
|
||||||
@@loggers.each_key do |key|
|
@@loggers.each_key do |key|
|
||||||
ActivityLogger.log(key, event)
|
ActivityLogger.log(key, event)
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,10 +29,6 @@ class ActivityPub::DeliveryWorker
|
||||||
def perform(json, source_account_id, inbox_url, options = {})
|
def perform(json, source_account_id, inbox_url, options = {})
|
||||||
return unless DeliveryFailureTracker.available?(inbox_url)
|
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
|
@options = options.with_indifferent_access
|
||||||
@json = json
|
@json = json
|
||||||
@source_account = Account.find(source_account_id)
|
@source_account = Account.find(source_account_id)
|
||||||
|
@ -40,6 +36,11 @@ class ActivityPub::DeliveryWorker
|
||||||
@host = Addressable::URI.parse(inbox_url).normalized_site
|
@host = Addressable::URI.parse(inbox_url).normalized_site
|
||||||
@performed = false
|
@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
|
perform_request
|
||||||
ensure
|
ensure
|
||||||
if @inbox_url.present?
|
if @inbox_url.present?
|
||||||
|
|
|
@ -7,8 +7,7 @@ class ActivityLogSubscriber
|
||||||
|
|
||||||
redis.subscribe('activity_log') do |on|
|
redis.subscribe('activity_log') do |on|
|
||||||
on.message do |channel, message|
|
on.message do |channel, message|
|
||||||
json = Oj.load(message, mode: :strict)
|
event = ActivityLogEvent.from_json_string(message)
|
||||||
event = ActivityLogEvent.new(json['type'], json['path'], json['data'])
|
|
||||||
|
|
||||||
ActivityLogAudienceHelper.audience(event)
|
ActivityLogAudienceHelper.audience(event)
|
||||||
.each { |username| ActivityLogger.log(username, event) }
|
.each { |username| ActivityLogger.log(username, event) }
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"timestamp":"2022-12-08T17:12:38Z",
|
"timestamp":"2022-12-08T17:12:38Z",
|
||||||
|
"sender": "https://other.org/users/alice",
|
||||||
"type": "inbound",
|
"type": "inbound",
|
||||||
"path": "https://example.com/users/bob/inbox",
|
"path": "https://example.com/users/bob/inbox",
|
||||||
"data": {
|
"data": {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"timestamp":"2022-12-08T17:12:38Z",
|
"timestamp":"2022-12-08T17:12:38Z",
|
||||||
|
"sender": "https://other.org/users/bob/",
|
||||||
"type": "inbound",
|
"type": "inbound",
|
||||||
"path": "https://example.com/inbox",
|
"path": "https://example.com/inbox",
|
||||||
"data": {
|
"data": {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"timestamp":"2022-12-08T17:12:38Z",
|
"timestamp":"2022-12-08T17:12:38Z",
|
||||||
|
"sender": "https://other.org/users/bob/",
|
||||||
"type": "inbound",
|
"type": "inbound",
|
||||||
"path": "https://example.com/inbox",
|
"path": "https://example.com/inbox",
|
||||||
"data": {
|
"data": {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"timestamp":"2022-12-08T17:12:38Z",
|
"timestamp":"2022-12-08T17:12:38Z",
|
||||||
|
"sender": "https://other.org/users/bob/",
|
||||||
"type": "inbound",
|
"type": "inbound",
|
||||||
"path": "https://example.com/inbox",
|
"path": "https://example.com/inbox",
|
||||||
"data": {
|
"data": {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"timestamp":"2022-12-08T17:12:38Z",
|
"timestamp":"2022-12-08T17:12:38Z",
|
||||||
|
"sender": "https://example.com/users/alice",
|
||||||
"type": "outbound",
|
"type": "outbound",
|
||||||
"path": "https://other.org/users/bob/inbox",
|
"path": "https://other.org/users/bob/inbox",
|
||||||
"data": {
|
"data": {
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
require 'json'
|
require 'json'
|
||||||
require 'rails_helper'
|
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
|
RSpec.describe ActivityLogger do
|
||||||
|
|
||||||
after(:each) do
|
after(:each) do
|
||||||
|
|
Loading…
Add table
Reference in a new issue