WIP
This commit is contained in:
parent
43a4bc09a2
commit
0dc4e5aba9
50
inc/activities/create.php
Normal file
50
inc/activities/create.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
namespace activities\create;
|
||||
|
||||
/*
|
||||
Create a new post or comment (depending on $activity["object"]["type"]),
|
||||
copying $activity["actor"] to the object's "attributedTo" and
|
||||
copying any recipients of the activity that aren't on the object
|
||||
to the object and vice-versa.
|
||||
*/
|
||||
function handle( $actor, $activity ) {
|
||||
if ( !(array_key_exists( "type", $activity ) && $activity["type"] === "Create") ) {
|
||||
return new WP_Error(
|
||||
'invalid_activity', __( 'Expecting a Create activity', 'activitypub' )
|
||||
);
|
||||
}
|
||||
if ( !array_key_exists( "object", $activity ) ) {
|
||||
return new WP_Error(
|
||||
'invalid_object', __( 'Expecting an object', 'activitypub' )
|
||||
);
|
||||
}
|
||||
if ( !array_key_exists( "actor", $activity ) ) {
|
||||
// TODO validate that $activity["actor"] is the URL of the $actor
|
||||
return new WP_Error(
|
||||
'invalid_actor', __( 'Expecting a valid actor', 'activitypub' )
|
||||
);
|
||||
}
|
||||
$object = $activity["object"];
|
||||
$actor_id = $activity["actor"];
|
||||
$object["attributedTo"] = $actor_id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function reconcile_receivers( $object, $activity ) {
|
||||
// TODO copy "audience", "to" "bto", "cc", "bcc"
|
||||
// to both object and activity from each other
|
||||
}
|
||||
|
||||
function copy_field_value( $field, $from, &$to ) {
|
||||
if ( array_key_exists( $field, $from ) ) {
|
||||
if ( array_key_exists ( $field, $to ) ) {
|
||||
$to[$field] = array_unique(
|
||||
array_merge( $from[$field], $to[$field] )
|
||||
);
|
||||
} else {
|
||||
$to[$field] = $from[$field];
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
@ -46,7 +46,9 @@ function persist_activity( $actor, $activity ) {
|
||||
function handle_activity( $actor, $activity ) {
|
||||
if ( !array_key_exists( "type", $activity ) ) {
|
||||
return new WP_Error(
|
||||
'invalid_activity', 'Invalid activity', array( 'status' => 400 )
|
||||
'invalid_activity',
|
||||
__( 'Invalid activity', 'activitypub' ),
|
||||
array( 'status' => 400 )
|
||||
);
|
||||
}
|
||||
switch ( $activity["type"] ) {
|
||||
@ -68,6 +70,9 @@ function handle_activity( $actor, $activity ) {
|
||||
break;
|
||||
case "Undo":
|
||||
break;
|
||||
default:
|
||||
// handle wrapping object in Create activity
|
||||
break;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user