@@ -47,6 +47,7 @@ public function __construct( Feed $friends_feed ) {
47
47
\add_action ( 'activitypub_inbox_announce ' , array ( $ this , 'handle_received_announce ' ), 15 , 2 );
48
48
\add_action ( 'activitypub_inbox_like ' , array ( $ this , 'handle_received_like ' ), 15 , 2 );
49
49
\add_action ( 'activitypub_inbox_undo ' , array ( $ this , 'handle_received_undo ' ), 15 , 2 );
50
+ \add_action ( 'activitypub_inbox_move ' , array ( $ this , 'handle_received_move ' ), 15 , 2 );
50
51
\add_action ( 'activitypub_handled_create ' , array ( $ this , 'activitypub_handled_create ' ), 10 , 4 );
51
52
52
53
\add_action ( 'friends_user_feed_activated ' , array ( $ this , 'queue_follow_user ' ), 10 );
@@ -789,6 +790,10 @@ public function handle_received_undo( $activity, $user_id ) {
789
790
return $ this ->handle_received_activity ( $ activity , $ user_id , 'undo ' );
790
791
}
791
792
793
+ public function handle_received_move ( $ activity , $ user_id ) {
794
+ return $ this ->handle_received_activity ( $ activity , $ user_id , 'move ' );
795
+ }
796
+
792
797
public function handle_received_delete ( $ activity , $ user_id ) {
793
798
return $ this ->handle_received_activity ( $ activity , $ user_id , 'delete ' );
794
799
}
@@ -840,6 +845,7 @@ public function handle_received_activity( $activity, $user_id, $type ) {
840
845
'unannounce ' ,
841
846
'like ' ,
842
847
'unlike ' ,
848
+ 'move ' ,
843
849
),
844
850
true
845
851
) ) {
@@ -924,6 +930,8 @@ protected function process_incoming_activity( $type, $activity, $user_id, $user_
924
930
return $ this ->handle_incoming_like ( $ activity , $ user_id );
925
931
case 'unlike ' :
926
932
return $ this ->handle_incoming_unlike ( $ activity , $ user_id );
933
+ case 'move ' :
934
+ return $ this ->handle_incoming_move ( $ activity , $ user_feed );
927
935
}
928
936
return null ;
929
937
}
@@ -1209,6 +1217,62 @@ public function handle_incoming_unlike( $activity, $user_id ) {
1209
1217
return true ;
1210
1218
}
1211
1219
1220
+ public function handle_incoming_move ( $ activity , User_Feed $ user_feed ) {
1221
+ $ old_url = $ activity ['object ' ];
1222
+ if ( $ user_feed ->get_url () !== $ old_url ) {
1223
+ $ this ->log ( 'Could not determine the right feed to be moved. Looking for ' . $ old_url . ', got ' . $ user_feed ->get_url () );
1224
+ return false ;
1225
+ }
1226
+
1227
+ $ feed = array (
1228
+ 'url ' => $ activity ['target ' ],
1229
+ 'mime-type ' => $ user_feed ->get_mime_type (),
1230
+ 'title ' => $ user_feed ->get_title (),
1231
+ 'parser ' => $ user_feed ->get_parser (),
1232
+ 'post-format ' => $ user_feed ->get_post_format (),
1233
+ 'active ' => $ user_feed ->is_active (),
1234
+ );
1235
+
1236
+ // Similar as in process_admin_edit_friend_feeds.
1237
+ if ( $ user_feed ->get_url () !== $ feed ['url ' ] ) {
1238
+ $ friend = $ user_feed ->get_friend_user ();
1239
+ do_action ( 'friends_user_feed_deactivated ' , $ user_feed );
1240
+
1241
+ if ( ! isset ( $ feed ['mime-type ' ] ) ) {
1242
+ $ feed ['mime-type ' ] = $ user_feed ->get_mime_type ();
1243
+ }
1244
+
1245
+ if ( $ feed ['active ' ] ) {
1246
+ $ new_feed = $ friend ->subscribe ( $ feed ['url ' ], $ feed );
1247
+ if ( ! is_wp_error ( $ new_feed ) ) {
1248
+ do_action ( 'friends_user_feed_activated ' , $ new_feed );
1249
+ }
1250
+ } else {
1251
+ $ new_feed = $ friend ->save_feed ( $ feed ['url ' ], $ feed );
1252
+ }
1253
+
1254
+ // Since the URL has changed, the above will create a new feed, therefore we need to delete the old one.
1255
+ $ user_feed ->delete ();
1256
+
1257
+ if ( is_wp_error ( $ new_feed ) ) {
1258
+ do_action ( 'friends_process_feed_item_submit_error ' , $ new_feed , $ feed );
1259
+ return $ new_feed ;
1260
+ }
1261
+
1262
+ do_action ( 'friends_process_feed_item_submit ' , $ new_feed , $ feed );
1263
+ $ new_feed ->update_last_log (
1264
+ sprintf (
1265
+ // translators: %s is the old URL.
1266
+ __ ( 'Moved from old URL: %s ' , 'friends ' ),
1267
+ $ user_feed ->get_url ()
1268
+ )
1269
+ );
1270
+ return $ new_feed ;
1271
+ }
1272
+
1273
+ return true ;
1274
+ }
1275
+
1212
1276
/**
1213
1277
* Queue a hook to run async.
1214
1278
*
0 commit comments