Persist created objects to the object table
This commit is contained in:
parent
be908690d4
commit
1a7d98e722
@ -30,11 +30,12 @@ function handle( $actor, $activity ) {
|
||||
$actor_id = $activity["actor"];
|
||||
$object["attributedTo"] = $actor_id;
|
||||
reconcile_receivers( $object, $activity );
|
||||
scrub_object( $object );
|
||||
$object = persist_object( $object );
|
||||
$activity["object"] = $object;
|
||||
return $activity;
|
||||
}
|
||||
|
||||
|
||||
function reconcile_receivers( &$object, &$activity ) {
|
||||
copy_field_value( "audience", $object, $activity );
|
||||
copy_field_value( "audience", $activity, $object );
|
||||
@ -42,14 +43,12 @@ function reconcile_receivers( &$object, &$activity ) {
|
||||
copy_field_value( "to", $object, $activity );
|
||||
copy_field_value( "to", $activity, $object );
|
||||
|
||||
copy_field_value( "bto", $object, $activity );
|
||||
copy_field_value( "bto", $activity, $object );
|
||||
|
||||
copy_field_value( "cc", $object, $activity );
|
||||
copy_field_value( "cc", $activity, $object );
|
||||
|
||||
// copy bcc and bto to activity for delivery but not to object
|
||||
copy_field_value( "bcc", $object, $activity );
|
||||
copy_field_value( "bcc", $activity, $object );
|
||||
copy_field_value( "bto", $object, $activity );
|
||||
}
|
||||
|
||||
function copy_field_value( $field, $from, &$to ) {
|
||||
@ -63,4 +62,27 @@ function copy_field_value( $field, $from, &$to ) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function scrub_object( &$object ) {
|
||||
unset( $object["bcc"] );
|
||||
unset( $object["bto"] );
|
||||
}
|
||||
|
||||
function persist_object( &$object ) {
|
||||
global $wpdb;
|
||||
$wpdb->insert( 'activitypub_objects', array( "object" => wp_json_encode( $object ) ) );
|
||||
// TODO hydrate $object["id"] to URL of object using $wpdb->insert_id
|
||||
}
|
||||
|
||||
function create_object_table() {
|
||||
global $wpdb;
|
||||
$wpdb->query(
|
||||
"
|
||||
CREATE TABLE IF NOT EXISTS activitypub_objects (
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
object TEXT NOT NULL
|
||||
);
|
||||
"
|
||||
);
|
||||
}
|
||||
?>
|
||||
|
@ -3,6 +3,7 @@ namespace init;
|
||||
|
||||
require_once plugin_dir_path( __FILE__ ) . '/outbox.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . '/api.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . '/activities/create.php';
|
||||
|
||||
add_action( 'rest_api_init', function() {
|
||||
\api\register_routes();
|
||||
@ -10,5 +11,6 @@ add_action( 'rest_api_init', function() {
|
||||
|
||||
add_action( 'activitypub_init', function() {
|
||||
\outbox\create_outbox_table();
|
||||
\activities\create\create_object_table();
|
||||
} );
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user