Skip to content

Commit 3aac52f

Browse files
authored
Emails: Make sure actor URL is set correctly (#1677)
1 parent 92e196e commit 3aac52f

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
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+
Email notifications for interactions with Brid.gy actors no longer trigger PHP Warnings.

includes/class-mailer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ private static function normalize_actor( $actor ) {
346346
if ( empty( $actor['url'] ) ) {
347347
$actor['url'] = $actor['id'];
348348
}
349+
$actor['url'] = object_to_uri( $actor['url'] );
349350

350351
if ( empty( $actor['webfinger'] ) ) {
351352
$actor['webfinger'] = '@' . ( $actor['preferredUsername'] ?? $actor['name'] ) . '@' . \wp_parse_url( $actor['url'], PHP_URL_HOST );

tests/includes/class-test-mailer.php

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Activitypub\Mailer;
1111
use Activitypub\Collection\Actors;
12-
use Activitypub\Notification;
1312
use WP_UnitTestCase;
1413

1514
/**
@@ -410,9 +409,8 @@ function ( $args ) use ( $user_id, $activity ) {
410409
} else {
411410
add_filter(
412411
'wp_mail',
413-
function ( $args ) {
412+
function () {
414413
$this->fail( 'Email should not be sent for public activity' );
415-
return $args;
416414
}
417415
);
418416

@@ -428,6 +426,56 @@ function ( $args ) {
428426
wp_delete_user( $user_id );
429427
}
430428

429+
/**
430+
* Test direct message notification from Bridgy.
431+
*
432+
* @covers ::direct_message
433+
*/
434+
public function test_direct_message_from_bridgy() {
435+
$activity = array(
436+
'actor' => 'https://example.com/author',
437+
'object' => array(
438+
'id' => 'https://example.com/post/1',
439+
'content' => 'Test direct message',
440+
),
441+
'to' => array( Actors::get_by_id( self::$user_id )->get_id() ),
442+
);
443+
444+
// Mock remote metadata.
445+
add_filter(
446+
'pre_get_remote_metadata_by_actor',
447+
function () {
448+
return array(
449+
'name' => 'Test Sender',
450+
'url' => array(
451+
'https://fed.brid.gy/r/https://example.com/author',
452+
453+
),
454+
);
455+
}
456+
);
457+
458+
// Capture email.
459+
add_filter(
460+
'wp_mail',
461+
function ( $args ) {
462+
$this->assertStringContainsString(
463+
'<a href="https://fed.brid.gy/r/https://example.com/author">@Test [email protected]</a>',
464+
$args['message']
465+
);
466+
return $args;
467+
}
468+
);
469+
470+
// Call the method.
471+
Mailer::direct_message( $activity, self::$user_id );
472+
473+
// Clean up.
474+
remove_all_filters( 'wp_before_load_template' );
475+
remove_all_filters( 'pre_get_remote_metadata_by_actor' );
476+
remove_all_filters( 'wp_mail' );
477+
}
478+
431479
/**
432480
* Data provider for direct message notification text.
433481
*

0 commit comments

Comments
 (0)