Skip to content

Commit

Permalink
Add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwiebe committed Jan 22, 2025
1 parent 106b390 commit 79f6b0e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
36 changes: 36 additions & 0 deletions includes/class-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,42 @@ private static function register_post_types() {
)
);

register_post_meta(
Outbox::POST_TYPE,
'activitypub_sent_json',
array(
'type' => 'string',
'description' => 'JSON activity for regular user',
'single' => true,
'sanitize_callback' => null,
'show_in_rest' => false,
)
);

register_post_meta(
Outbox::POST_TYPE,
'activitypub_sent_inboxes',
array(
'type' => 'array',
'description' => 'List of inboxes for regular user',
'single' => true,
'sanitize_callback' => null,
'show_in_rest' => false,
)
);

register_post_meta(
Outbox::POST_TYPE,
'activitypub_send_log',
array(
'type' => 'array',
'description' => 'Delivery logs for the activity',
'single' => false,
'sanitize_callback' => null,
'show_in_rest' => false,
)
);

// Both User and Blog Extra Fields types have the same args.
$args = array(
'labels' => array(
Expand Down
18 changes: 17 additions & 1 deletion includes/class-dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,24 @@ private static function send_activity_to_followers( $activity, $actor_id, $outbo

$json = $activity->to_json();

// We will store the json as generated by the transformer, even though it 's also in plaintext in $outbox_item->post_content
// This will also allow us to keep the logs below leaner.
\add_post_meta( $outbox_item->ID, 'activitypub_sent_json', $json );
// This will allow error checking later, that all inboxes have been sent.
\add_post_meta( $outbox_item->ID, 'activitypub_sent_inboxes', $inboxes, true );

foreach ( $inboxes as $inbox ) {
safe_remote_post( $inbox, $json, $actor_id );
$response = safe_remote_post( $inbox, $json, $actor_id );
$to_log = array(
'error' => null,
'inbox' => $inbox,
'code' => $response['code'],
'delivered' => 202 === $response['code'],
);
if ( ! $to_log['delivered'] ) {
$to_log['error'] = $response['body'];
}
\add_post_meta( $outbox_item->ID, 'activitypub_send_log', $to_log );
}

$outbox_item->post_status = 'publish';
Expand Down

0 comments on commit 79f6b0e

Please sign in to comment.