associate comments to back compat post

This commit is contained in:
Django Doucet 2022-11-18 22:19:08 -07:00
parent b1f64f6828
commit 5dbf365c58
2 changed files with 39 additions and 2 deletions

View file

@ -356,6 +356,43 @@ function url_to_authorid( $url ) {
return 0;
}
/**
* Verify if in_replyto_url is a local Post,
* (For backwards compatibility)
*
* @param string activitypub object id URI
* @return int post_id
*/
function url_to_postid( $in_replyto_url ) {
if ( !empty( $in_replyto_url ) ) {
$tentative_postid = \url_to_postid( $in_replyto_url );
if ( is_null( $tentative_postid ) ) {
$post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) );
$query_args = array(
'type' => $post_types,
'meta_query' => array(
array(
'key' => '_activitypub_permalink_compat',
'value' => $in_replyto_url,
),
),
);
$posts_query = new \WP_Query();
$posts = $posts_query->query( $query_args );
$found_post_ids = array();
if ( $posts ) {
foreach ( $posts as $post ) {
$found_post_ids[] = $post->comment_ID;
}
return $found_post_ids[0];
}
} else {
return $tentative_postid;
}
}
return null;
}
/**
* Verify if in_replyto_url is a local comment,
* Or if it is a previously received remote comment

View file

@ -415,7 +415,7 @@ class Inbox {
$audience = \Activitypub\get_audience( $object );
if ( isset( $object['object']['inReplyTo'] ) ) {
$comment_parent_id = \Activitypub\url_to_commentid( \esc_url_raw( $object['object']['inReplyTo'] ) );
$comment_parent_id = \Activitypub\url_to_commentid( \esc_url_raw( $object['object']['inReplyTo'] ) ); // Only checks ap_comment_id for local or source_url for remote
if ( ! is_null( $comment_parent_id ) ) {
//inReplyTo a known local comment
@ -423,7 +423,7 @@ class Inbox {
$comment_post_id = $comment_parent->comment_post_ID;
} else {
//inReplyTo a known post
$comment_post_id = \url_to_postid( $object['object']['inReplyTo'] );
$comment_post_id = \Activitypub\url_to_postid( $object['object']['inReplyTo'] );
}
}