Skip to content

Commit 5c39166

Browse files
committed
Merge branch 'trunk' into add/reader
2 parents abf66f9 + 0ba13f9 commit 5c39166

23 files changed

+1487
-169
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Respect WordPress "show avatars" setting for remote actor avatars.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Add scheduled cleanup for remote posts, preserving posts with local user interactions.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
applyTo: "build/**"
3+
excludeAgent: "coding-agent"
4+
---
5+
6+
Do not review these files. The `build/` directory contains generated assets.

build/followers/index.asset.php

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/followers/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/followers/render.php

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/class-avatars.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public static function pre_get_avatar_data( $args, $id_or_email ) {
4747
return $args;
4848
}
4949

50+
// Respect WordPress "show avatars" setting.
51+
if ( ! \get_option( 'show_avatars' ) ) {
52+
return $args;
53+
}
54+
5055
$avatar = null;
5156

5257
// First, try to get avatar from remote actor.

includes/class-blocklist-subscriptions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public static function parse_csv_string( $content ) {
169169
}
170170

171171
// Parse first line to detect format.
172-
$first_line = \str_getcsv( $lines[0] );
172+
$first_line = \str_getcsv( $lines[0], ',', '"', '\\' );
173173
$first_cell = \trim( $first_line[0] ?? '' );
174174
$has_header = \str_starts_with( $first_cell, '#' ) || 'domain' === \strtolower( $first_cell );
175175

@@ -189,7 +189,7 @@ public static function parse_csv_string( $content ) {
189189

190190
// Process each line.
191191
foreach ( $lines as $line ) {
192-
$row = \str_getcsv( $line );
192+
$row = \str_getcsv( $line, ',', '"', '\\' );
193193
$domain = \trim( $row[ $domain_index ] ?? '' );
194194

195195
// Skip empty lines and comments.

includes/class-blocks.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public static function enqueue_editor_assets() {
4646
'user' => \admin_url( 'profile.php#activitypub' ),
4747
'blog' => \admin_url( 'options-general.php?page=activitypub&tab=blog-profile' ),
4848
),
49+
'showAvatars' => (bool) \get_option( 'show_avatars' ),
4950
);
5051
wp_localize_script( 'wp-editor', '_activityPubOptions', $data );
5152

includes/class-scheduler.php

Lines changed: 37 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Activitypub\Collection\Actors;
1313
use Activitypub\Collection\Inbox;
1414
use Activitypub\Collection\Outbox;
15+
use Activitypub\Collection\Posts;
1516
use Activitypub\Collection\Remote_Actors;
1617
use Activitypub\Scheduler\Actor;
1718
use Activitypub\Scheduler\Collection_Sync;
@@ -61,14 +62,16 @@ public static function init() {
6162
\add_action( 'activitypub_reprocess_outbox', array( self::class, 'reprocess_outbox' ) );
6263
\add_action( 'activitypub_outbox_purge', array( self::class, 'purge_outbox' ) );
6364
\add_action( 'activitypub_inbox_purge', array( self::class, 'purge_inbox' ) );
65+
\add_action( 'activitypub_ap_post_purge', array( self::class, 'purge_ap_posts' ) );
6466
\add_action( 'activitypub_inbox_create_item', array( self::class, 'process_inbox_activity' ) );
6567
\add_action( 'activitypub_sync_blocklist_subscriptions', array( Blocklist_Subscriptions::class, 'sync_all' ) );
6668

6769
\add_action( 'post_activitypub_add_to_outbox', array( self::class, 'schedule_outbox_activity_for_federation' ) );
6870
\add_action( 'post_activitypub_add_to_outbox', array( self::class, 'schedule_announce_activity' ), 10, 4 );
6971

70-
\add_action( 'update_option_activitypub_outbox_purge_days', array( self::class, 'handle_outbox_purge_days_update' ), 10, 2 );
71-
\add_action( 'update_option_activitypub_inbox_purge_days', array( self::class, 'handle_inbox_purge_days_update' ), 10, 2 );
72+
\add_action( 'update_option_activitypub_outbox_purge_days', array( self::class, 'update_outbox_purge_schedule' ), 10, 2 );
73+
\add_action( 'update_option_activitypub_inbox_purge_days', array( self::class, 'update_inbox_purge_schedule' ), 10, 2 );
74+
\add_action( 'update_option_activitypub_ap_post_purge_days', array( self::class, 'update_ap_post_purge_schedule' ), 10, 2 );
7275
}
7376

7477
/**
@@ -134,6 +137,10 @@ public static function register_schedules() {
134137
\wp_schedule_event( time(), 'daily', 'activitypub_inbox_purge' );
135138
}
136139

140+
if ( ! \wp_next_scheduled( 'activitypub_ap_post_purge' ) ) {
141+
\wp_schedule_event( time(), 'daily', 'activitypub_ap_post_purge' );
142+
}
143+
137144
if ( ! \wp_next_scheduled( 'activitypub_sync_blocklist_subscriptions' ) ) {
138145
\wp_schedule_event( time(), 'weekly', 'activitypub_sync_blocklist_subscriptions' );
139146
}
@@ -150,6 +157,7 @@ public static function deregister_schedules() {
150157
\wp_unschedule_hook( 'activitypub_reprocess_outbox' );
151158
\wp_unschedule_hook( 'activitypub_outbox_purge' );
152159
\wp_unschedule_hook( 'activitypub_inbox_purge' );
160+
\wp_unschedule_hook( 'activitypub_ap_post_purge' );
153161
\wp_unschedule_hook( 'activitypub_sync_blocklist_subscriptions' );
154162
}
155163

@@ -315,66 +323,24 @@ public static function reprocess_outbox() {
315323
* Purge outbox items based on a schedule.
316324
*/
317325
public static function purge_outbox() {
318-
$total_posts = (int) wp_count_posts( Outbox::POST_TYPE )->publish;
319-
if ( $total_posts <= 20 ) {
320-
return;
321-
}
322-
323-
$days = (int) get_option( 'activitypub_outbox_purge_days', 180 );
324-
$post_ids = \get_posts(
325-
array(
326-
'post_type' => Outbox::POST_TYPE,
327-
'post_status' => 'any',
328-
'fields' => 'ids',
329-
'numberposts' => -1,
330-
'date_query' => array(
331-
array(
332-
'before' => gmdate( 'Y-m-d', time() - ( $days * DAY_IN_SECONDS ) ),
333-
),
334-
),
335-
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
336-
'meta_query' => array(
337-
array(
338-
'key' => '_activitypub_activity_type',
339-
'value' => 'Follow',
340-
'compare' => '!=',
341-
),
342-
),
343-
)
344-
);
345-
346-
foreach ( $post_ids as $post_id ) {
347-
\wp_delete_post( $post_id, true );
348-
}
326+
$days = (int) \get_option( 'activitypub_outbox_purge_days', 180 );
327+
Outbox::purge( $days );
349328
}
350329

351330
/**
352331
* Purge inbox items based on a schedule.
353332
*/
354333
public static function purge_inbox() {
355-
$total_posts = (int) wp_count_posts( Inbox::POST_TYPE )->publish;
356-
if ( $total_posts <= 200 ) {
357-
return;
358-
}
359-
360-
$days = (int) get_option( 'activitypub_inbox_purge_days', 180 );
361-
$post_ids = \get_posts(
362-
array(
363-
'post_type' => Inbox::POST_TYPE,
364-
'post_status' => 'any',
365-
'fields' => 'ids',
366-
'numberposts' => -1,
367-
'date_query' => array(
368-
array(
369-
'before' => gmdate( 'Y-m-d', time() - ( $days * DAY_IN_SECONDS ) ),
370-
),
371-
),
372-
)
373-
);
334+
$days = (int) \get_option( 'activitypub_inbox_purge_days', 180 );
335+
Inbox::purge( $days );
336+
}
374337

375-
foreach ( $post_ids as $post_id ) {
376-
\wp_delete_post( $post_id, true );
377-
}
338+
/**
339+
* Purge remote posts based on a schedule.
340+
*/
341+
public static function purge_ap_posts() {
342+
$days = (int) \get_option( 'activitypub_ap_post_purge_days', 30 );
343+
Posts::purge( $days );
378344
}
379345

380346
/**
@@ -430,7 +396,7 @@ public static function process_inbox_activity( $activity_id ) {
430396
* @param int $old_value The old value.
431397
* @param int $value The new value.
432398
*/
433-
public static function handle_outbox_purge_days_update( $old_value, $value ) {
399+
public static function update_outbox_purge_schedule( $old_value, $value ) {
434400
if ( 0 === (int) $value ) {
435401
\wp_clear_scheduled_hook( 'activitypub_outbox_purge' );
436402
} elseif ( ! \wp_next_scheduled( 'activitypub_outbox_purge' ) ) {
@@ -444,14 +410,28 @@ public static function handle_outbox_purge_days_update( $old_value, $value ) {
444410
* @param int $old_value The old value.
445411
* @param int $value The new value.
446412
*/
447-
public static function handle_inbox_purge_days_update( $old_value, $value ) {
413+
public static function update_inbox_purge_schedule( $old_value, $value ) {
448414
if ( 0 === (int) $value ) {
449415
\wp_clear_scheduled_hook( 'activitypub_inbox_purge' );
450416
} elseif ( ! \wp_next_scheduled( 'activitypub_inbox_purge' ) ) {
451417
\wp_schedule_event( \time(), 'daily', 'activitypub_inbox_purge' );
452418
}
453419
}
454420

421+
/**
422+
* Update schedules when remote posts purge days settings change.
423+
*
424+
* @param int $old_value The old value.
425+
* @param int $value The new value.
426+
*/
427+
public static function update_ap_post_purge_schedule( $old_value, $value ) {
428+
if ( 0 === (int) $value ) {
429+
\wp_clear_scheduled_hook( 'activitypub_ap_post_purge' );
430+
} elseif ( ! \wp_next_scheduled( 'activitypub_ap_post_purge' ) ) {
431+
\wp_schedule_event( \time(), 'daily', 'activitypub_ap_post_purge' );
432+
}
433+
}
434+
455435
/**
456436
* Asynchronously runs batch processing routines.
457437
*

0 commit comments

Comments
 (0)