Skip to content

Commit 5a5d523

Browse files
authored
Support multiple public audience identifiers in activities (#2206)
1 parent f538fea commit 5a5d523

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: changed
3+
4+
Improved checks to better identify public Activities.

includes/constants.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,14 @@
7373
define( 'ACTIVITYPUB_CONTENT_VISIBILITY_QUIET_PUBLIC', 'quiet_public' );
7474
define( 'ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE', 'private' );
7575
define( 'ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL', 'local' );
76+
77+
78+
// Identifiers that mark an Activity as Public.
79+
define(
80+
'ACTIVITYPUB_PUBLIC_AUDIENCE_IDENTIFIERS',
81+
array(
82+
'https://www.w3.org/ns/activitystreams#Public',
83+
'as:Public',
84+
'Public', // For backwards compatibility.
85+
)
86+
);

includes/functions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ function extract_recipients_from_activity( $data ) {
564564
/**
565565
* Check if passed Activity is Public.
566566
*
567+
* @see https://github.com/w3c/activitypub/issues/404#issuecomment-2926310561
568+
*
567569
* @param Base_Object|array $data The Activity object as Base_Object or array.
568570
*
569571
* @return boolean True if public, false if not.
@@ -575,7 +577,7 @@ function is_activity_public( $data ) {
575577

576578
$recipients = extract_recipients_from_activity( $data );
577579

578-
return in_array( 'https://www.w3.org/ns/activitystreams#Public', $recipients, true );
580+
return ! empty( array_intersect( $recipients, ACTIVITYPUB_PUBLIC_AUDIENCE_IDENTIFIERS ) );
579581
}
580582

581583
/**

tests/includes/class-test-functions.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,30 @@ public function public_activity_provider() {
10061006
),
10071007
false,
10081008
),
1009+
array(
1010+
array(
1011+
'to' => 'as:Public',
1012+
'cc' => '',
1013+
'object' => '',
1014+
),
1015+
true,
1016+
),
1017+
array(
1018+
array(
1019+
'to' => '',
1020+
'cc' => 'as:Public',
1021+
'object' => '',
1022+
),
1023+
true,
1024+
),
1025+
array(
1026+
array(
1027+
'to' => '',
1028+
'cc' => 'Public',
1029+
'object' => '',
1030+
),
1031+
true,
1032+
),
10091033
);
10101034
}
10111035
}

0 commit comments

Comments
 (0)