remove comment_type

This commit is contained in:
Django Doucet 2022-12-10 13:36:49 -07:00
parent e48986dd99
commit b04538a2ab
2 changed files with 13 additions and 23 deletions

View file

@ -27,8 +27,8 @@ class Comments {
*/ */
public static function preprocess_comment( $commentdata ) { public static function preprocess_comment( $commentdata ) {
// only process replies from local actors // only process replies from local actors
if ( ! empty( $commentdata['user_id'] ) ) { $user = \get_userdata( $commentdata['user_id'] );
$commentdata['comment_type'] = 'activitypub'; if ( $user->has_cap( 'publish_post' ) ) {
// transform webfinger mentions to links and add @mentions to cc // transform webfinger mentions to links and add @mentions to cc
$tagged_content = \Activitypub\transform_tags( $commentdata['comment_content'] ); $tagged_content = \Activitypub\transform_tags( $commentdata['comment_content'] );
$commentdata['comment_content'] = $tagged_content['content']; $commentdata['comment_content'] = $tagged_content['content'];
@ -42,18 +42,14 @@ class Comments {
* postprocess_comment for federating replies and inbox-forwarding * postprocess_comment for federating replies and inbox-forwarding
*/ */
public static function postprocess_comment( $comment_id, $comment_approved, $commentdata ) { public static function postprocess_comment( $comment_id, $comment_approved, $commentdata ) {
//Admin users comments bypass transition_comment_status (auto approved) //Adminstrator role users comments bypass transition_comment_status (auto approved)
$user = \get_userdata( $commentdata['user_id'] ); $user = \get_userdata( $commentdata['user_id'] );
if ( 'activitypub' === $commentdata['comment_type'] ) { if (
if ( ( 1 === $comment_approved ) &&
( 1 === $comment_approved ) && \in_array( 'administrator', $user->roles )
! empty( $commentdata['user_id'] ) && ) {
\in_array( 'administrator', $user->roles ) // Only for Admins
) { \wp_schedule_single_event( \time(), 'activitypub_send_comment_activity', array( $comment_id ) );
// Only for Admins
$mentions = \get_comment_meta( $comment_id, 'mentions', true );
\wp_schedule_single_event( \time(), 'activitypub_send_comment_activity', array( $comment_id ) );
}
} }
} }

View file

@ -435,7 +435,7 @@ class Inbox {
} }
// if avatar is set // if avatar is set
if ( ! empty( $meta['icon']['url'] ) ) { if ( ! empty( $meta['icon']['url'] ) ) {
$avatar_url = \esc_attr( $meta['icon']['url'] ); $avatar_url = \esc_url_raw( $meta['icon']['url'] );
} }
//Only create WP_Comment for public replies to local posts //Only create WP_Comment for public replies to local posts
@ -450,7 +450,7 @@ class Inbox {
'comment_author' => $name, 'comment_author' => $name,
'comment_author_url' => \esc_url_raw( $object['actor'] ), 'comment_author_url' => \esc_url_raw( $object['actor'] ),
'comment_content' => \wp_filter_kses( $object['object']['content'] ), 'comment_content' => \wp_filter_kses( $object['object']['content'] ),
'comment_type' => 'activitypub', 'comment_type' => '',
'comment_author_email' => '', 'comment_author_email' => '',
'comment_parent' => $comment_parent_id, 'comment_parent' => $comment_parent_id,
'comment_meta' => array( 'comment_meta' => array(
@ -485,8 +485,6 @@ class Inbox {
*/ */
public static function handle_update( $object, $user_id ) { public static function handle_update( $object, $user_id ) {
$meta = \Activitypub\get_remote_metadata_by_actor( $object['actor'] ); $meta = \Activitypub\get_remote_metadata_by_actor( $object['actor'] );
$avatar_url = null;
$audience = \Activitypub\get_audience( $object );
//Determine comment_ID //Determine comment_ID
$object_comment_id = \Activitypub\url_to_commentid( \esc_url_raw( $object['object']['id'] ) ); $object_comment_id = \Activitypub\url_to_commentid( \esc_url_raw( $object['object']['id'] ) );
@ -494,9 +492,9 @@ class Inbox {
//found a local comment id //found a local comment id
$commentdata = \get_comment( $object_comment_id, ARRAY_A ); $commentdata = \get_comment( $object_comment_id, ARRAY_A );
$commentdata['comment_author'] = \esc_attr( $meta['name'] ? $meta['name'] : $meta['preferredUsername'] );
//$commentdata['comment_ID'] = \esc_url_raw( $object_comment_id );
$commentdata['comment_content'] = \wp_filter_kses( $object['object']['content'] ); $commentdata['comment_content'] = \wp_filter_kses( $object['object']['content'] );
$commentdata['comment_meta']['avatar_url'] = \esc_url_raw($meta['icon']['url']);
$commentdata['comment_meta']['ap_published'] = \wp_date( 'Y-m-d H:i:s', strtotime( $object['object']['published'] ) ); $commentdata['comment_meta']['ap_published'] = \wp_date( 'Y-m-d H:i:s', strtotime( $object['object']['published'] ) );
$commentdata['comment_meta']['ap_last_modified'] = $object['object']['updated']; $commentdata['comment_meta']['ap_last_modified'] = $object['object']['updated'];
$commentdata['comment_meta']['ap_object'] = \serialize( $object ); $commentdata['comment_meta']['ap_object'] = \serialize( $object );
@ -523,10 +521,6 @@ class Inbox {
* @param int $user_id The id of the local blog-user * @param int $user_id The id of the local blog-user
*/ */
public static function handle_delete( $object, $user_id ) { public static function handle_delete( $object, $user_id ) {
$meta = \Activitypub\get_remote_metadata_by_actor( $object['actor'] );
$avatar_url = null;
$audience = \Activitypub\get_audience( $object );
if ( ! isset( $object['object']['id'] ) ) { if ( ! isset( $object['object']['id'] ) ) {
return; return;
} }