@@ -22,16 +22,17 @@ class Update {
2222 * Initialize the class, registering WordPress hooks.
2323 */
2424 public static function init () {
25- \add_action ( 'activitypub_inbox_update ' , array ( self ::class, 'handle_update ' ), 10 , 2 );
25+ \add_action ( 'activitypub_inbox_update ' , array ( self ::class, 'handle_update ' ), 10 , 3 );
2626 }
2727
2828 /**
2929 * Handle "Update" requests.
3030 *
31- * @param array $activity The Activity object.
32- * @param int $user_id The user ID. Always null for Update activities.
31+ * @param array $activity The Activity object.
32+ * @param int $user_id The user ID. Always null for Update activities.
33+ * @param \Activitypub\Activity\Activity $activity_object The activity object. Default null.
3334 */
34- public static function handle_update ( $ activity , $ user_id ) {
35+ public static function handle_update ( $ activity , $ user_id, $ activity_object ) {
3536 $ object_type = $ activity ['object ' ]['type ' ] ?? '' ;
3637
3738 switch ( $ object_type ) {
@@ -60,7 +61,7 @@ public static function handle_update( $activity, $user_id ) {
6061 case 'Video ' :
6162 case 'Event ' :
6263 case 'Document ' :
63- self ::update_object ( $ activity , $ user_id );
64+ self ::update_object ( $ activity , $ user_id, $ activity_object );
6465 break ;
6566
6667 /*
@@ -76,21 +77,42 @@ public static function handle_update( $activity, $user_id ) {
7677 /**
7778 * Update an Object.
7879 *
79- * @param array $activity The Activity object.
80- * @param int $user_id The user ID. Always null for Update activities.
80+ * @param array $activity The Activity object.
81+ * @param int $user_id The user ID. Always null for Update activities.
82+ * @param \Activitypub\Activity\Activity $activity_object The activity object. Default null.
8183 */
82- public static function update_object ( $ activity , $ user_id ) {
83- $ result = new \WP_Error ( 'activitypub_update_failed ' , 'Update failed ' );
84+ public static function update_object ( $ activity , $ user_id , $ activity_object ) {
85+ $ result = new \WP_Error ( 'activitypub_update_failed ' , 'Update failed ' );
86+ $ updated = true ;
8487
8588 // Check for private and/or direct messages.
8689 if ( is_activity_reply ( $ activity ) ) {
8790 $ comment_data = Interactions::update_comment ( $ activity );
8891
89- if ( ! empty ( $ comment_data ['comment_ID ' ] ) ) {
92+ if ( false === $ comment_data ) {
93+ $ updated = false ;
94+ } elseif ( ! empty ( $ comment_data ['comment_ID ' ] ) ) {
9095 $ result = \get_comment ( $ comment_data ['comment_ID ' ] );
9196 }
9297 } else {
9398 $ result = Posts::update ( $ activity );
99+
100+ if ( \is_wp_error ( $ result ) && 'activitypub_post_not_found ' === $ result ->get_error_code () ) {
101+ $ updated = false ;
102+ }
103+ }
104+
105+ // There is no object to update, try to trigger create instead.
106+ if ( ! $ updated ) {
107+ /**
108+ * Fires when a Create activity is received for an existing object.
109+ *
110+ * @param array $activity The activity-object.
111+ * @param int $user_id The id of the local blog-user.
112+ * @param \Activitypub\Activity\Activity $activity_object The activity object.
113+ */
114+ \do_action ( 'activitypub_inbox_create ' , $ activity , $ user_id , $ activity_object );
115+ return false ;
94116 }
95117
96118 $ success = ( $ result && ! \is_wp_error ( $ result ) );
0 commit comments