Make the whole outbox code path work
This commit is contained in:
parent
78049c61bf
commit
188229a7ab
@ -67,11 +67,33 @@ function persist_activity( $activity ) {
|
||||
}
|
||||
$activitypub_id = $activity['id'];
|
||||
$type = $activity['type'];
|
||||
$wpdb->replace( 'pterotype_activities', array(
|
||||
'activitypub_id' => $activitypub_id,
|
||||
'type' => $type,
|
||||
'activity' => wp_json_encode( $activity )
|
||||
$row = $wpdb->get_row( $wpdb->prepare(
|
||||
'SELECT * FROM pterotype_activities WHERE activitypub_id = %s', $activitypub_id
|
||||
) );
|
||||
$res = true;
|
||||
if ( $row === null ) {
|
||||
$res = $wpdb->insert(
|
||||
'pterotype_activities',
|
||||
array(
|
||||
'activitypub_id' => $activitypub_id,
|
||||
'type' => $type,
|
||||
'activity' => wp_json_encode( $activity )
|
||||
),
|
||||
'%s'
|
||||
);
|
||||
} else {
|
||||
$res = $wpdb->update(
|
||||
'pterotype_activities',
|
||||
array(
|
||||
'activitypub_id' => $activitypub_id,
|
||||
'type' => $type,
|
||||
'activity' => wp_json_encode( $activity )
|
||||
),
|
||||
array( 'id' => $row->id ),
|
||||
'%s',
|
||||
'%d'
|
||||
);
|
||||
}
|
||||
return $activity;
|
||||
}
|
||||
|
||||
@ -97,15 +119,16 @@ function create_local_activity( $activity ) {
|
||||
$activity_id = $wpdb->insert_id;
|
||||
$activity_url = get_rest_url( null, sprintf( '/pterotype/v1/activity/%d', $activity_id ) );
|
||||
$activity['id'] = $activity_url;
|
||||
$res = $wpdb->replace(
|
||||
$res = $wpdb->update(
|
||||
'pterotype_activities',
|
||||
array(
|
||||
'id' => $activity_id,
|
||||
'activitypub_id' => $activity_url,
|
||||
'type' => $type,
|
||||
'activity' => wp_json_encode( $activity ),
|
||||
),
|
||||
array( '%d', '%s', '%s', '%s' )
|
||||
array( 'id' => $activity_id ),
|
||||
'%s',
|
||||
'%d'
|
||||
);
|
||||
if ( !$res ) {
|
||||
return new \WP_Error(
|
||||
|
@ -115,10 +115,10 @@ function initialize_actors() {
|
||||
|
||||
function create_actor( $slug, $type ) {
|
||||
global $wpdb;
|
||||
$wpdb->replace(
|
||||
'pterotype_actors',
|
||||
array( 'slug' => $slug, 'type' => $type ),
|
||||
'%s'
|
||||
);
|
||||
return $wpdb->query( $wpdb->prepare(
|
||||
'INSERT IGNORE INTO pterotype_actors(slug, type) VALUES(%s, %s)',
|
||||
$slug,
|
||||
$type
|
||||
) );
|
||||
}
|
||||
?>
|
||||
|
@ -14,7 +14,8 @@ function request_follow( $actor_id, $object_id ) {
|
||||
'actor_id' => $actor_id,
|
||||
'object_id' => $object_id,
|
||||
'state' => PTEROTYPE_FOLLOW_PENDING
|
||||
)
|
||||
),
|
||||
array( '%d', '%d', '%s' )
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -37,15 +37,16 @@ function create_local_object( $object ) {
|
||||
$object['id'] = $object_url;
|
||||
$object['likes'] = $object_likes;
|
||||
$object['shares'] = $object_shares;
|
||||
$res = $wpdb->replace(
|
||||
$res = $wpdb->update(
|
||||
'pterotype_objects',
|
||||
array (
|
||||
'id' => $object_id,
|
||||
'activitypub_id' => $object_url,
|
||||
'type' => $type,
|
||||
'object' => wp_json_encode( $object )
|
||||
),
|
||||
array( '%d', '%s', '%s', '%s' )
|
||||
array( 'id' => $object_id ),
|
||||
'%s',
|
||||
'%d'
|
||||
);
|
||||
if ( !$res ) {
|
||||
return new \WP_Error(
|
||||
@ -76,7 +77,7 @@ function upsert_object( $object ) {
|
||||
);
|
||||
}
|
||||
$row = $wpdb->get_row( $wpdb->prepare(
|
||||
'SELECT * FROM pterotype_objects WHERE activitypub_url = %s', $object['id']
|
||||
'SELECT * FROM pterotype_objects WHERE activitypub_id = %s', $object['id']
|
||||
) );
|
||||
$res = true;
|
||||
if ( $row === null ) {
|
||||
@ -86,18 +87,20 @@ function upsert_object( $object ) {
|
||||
'activitypub_id' => $object['id'],
|
||||
'type' => $object['type'],
|
||||
'object' => wp_json_encode( $object )
|
||||
)
|
||||
),
|
||||
'%s'
|
||||
);
|
||||
} else {
|
||||
$res = $wpdb->replace(
|
||||
$res = $wpdb->update(
|
||||
'pterotype_objects',
|
||||
array(
|
||||
'id' => $row->id,
|
||||
'activitypub_id' => $object['id'],
|
||||
'type' => $object['type'],
|
||||
'object' => wp_json_encode( $object )
|
||||
),
|
||||
array( '%d', '%s', '%s', '%s' )
|
||||
array( 'id' => $row->id ),
|
||||
'%s',
|
||||
'%d'
|
||||
);
|
||||
$row = new stdClass();
|
||||
$row->id = $wpdb->insert_id;
|
||||
@ -219,14 +222,15 @@ function delete_object( $object ) {
|
||||
}
|
||||
$activitypub_id = $object['id'];
|
||||
$tombstone = make_tombstone( $object );
|
||||
$res = $wpdb->replace(
|
||||
$res = $wpdb->update(
|
||||
'pterotype_objects',
|
||||
array(
|
||||
'activitypub_id' => $activitypub_id,
|
||||
'type' => $tombstone['type'],
|
||||
'object' => wp_json_encode( $tombstone ),
|
||||
),
|
||||
array( '%s', '%s', '%s' )
|
||||
array( 'activitypub_id' => $activitypub_id ),
|
||||
'%s',
|
||||
'%s'
|
||||
);
|
||||
if ( !$res ) {
|
||||
return new \WP_Error( 'db_error', __( 'Error deleting object', 'pterotype' ) );
|
||||
|
@ -25,6 +25,7 @@ require_once plugin_dir_path( __FILE__ ) . 'activities/undo.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . '../util.php';
|
||||
|
||||
function handle_activity( $actor_slug, $activity ) {
|
||||
xdebug_break();
|
||||
// TODO handle authentication/authorization
|
||||
$activity = \util\dereference_object( $activity );
|
||||
if ( is_wp_error( $activity ) ) {
|
||||
@ -113,7 +114,6 @@ function handle_activity( $actor_slug, $activity ) {
|
||||
return $activity;
|
||||
}
|
||||
// the activity may have changed while processing side effects, so persist the new version
|
||||
// TODO why was 'id' missing from the activity here?
|
||||
$activity = \activities\persist_activity( $activity );
|
||||
if ( is_wp_error( $activity ) ) {
|
||||
return $activity;
|
||||
|
Loading…
Reference in New Issue
Block a user