-
Notifications
You must be signed in to change notification settings - Fork 85
Improved recipient handling for clarity and added better inbox support #2210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
523defe
Refactor recipient extraction and add unit tests
pfefferle 51fe673
Rename parameter from attribute to property in function
pfefferle 3b79444
Merge branch 'trunk' into add/inbox-visibility
pfefferle d25fd5f
Refactor recipient extraction and object_to_uri handling
pfefferle 70ce80f
Filter empty values from recipients array
pfefferle 79429da
Improve object_to_uri fallback and update related tests
pfefferle 858672f
Merge branch 'trunk' into add/inbox-visibility
pfefferle 35dbe06
Refactor recipient extraction and add Audience trait
pfefferle 615bd19
Add visibility parameter to ActivityPub inbox actions
pfefferle 93cf677
Refactor handle_create to use visibility parameter
pfefferle 5e823d1
Set default private visibility for certain activity types
pfefferle 17fb6f9
Reorder activity types in visibility check
pfefferle 2e62107
Add changelog
matticbot be0b67f
Add unit tests for Audience trait in REST API
pfefferle 4d6bb2f
Merge branch 'trunk' into add/inbox-visibility
pfefferle 17ca93c
Merge branch 'trunk' into add/inbox-visibility
pfefferle 23b92ea
Use global namespace for array functions
pfefferle 4ed4a4a
Update object_to_uri to return empty string on failure
pfefferle 8a731d8
Move recipient extraction logic to Inbox_Controller
pfefferle eb12652
Refactor activity visibility logic and remove Audience trait
pfefferle 698f36d
Rename get_recipients to get_local_recipients
pfefferle 2d99fbe
Rename test methods to use get_local_recipients
pfefferle 7838f06
Prevent duplicate checkstyle annotations in PHPUnit workflow
pfefferle 9c4af52
Remove redundant @covers annotations in tests
pfefferle 1c6a274
Refactor object_to_uri to remove default empty string
pfefferle 4d40df6
Merge branch 'trunk' into add/inbox-visibility
pfefferle 0154560
Fix object_to_uri to require 'id' and update related tests
pfefferle 107e0f6
Merge branch 'trunk' into add/inbox-visibility
pfefferle 6d6d923
Refactor activity visibility handling in inbox actions
pfefferle 84c634a
Improve activity visibility checks and expand Create handler tests
pfefferle 359496d
Update changelog for recipient and visibility handling
pfefferle b9e19fc
Fix indentation in docblock for do_action hook
pfefferle 7001481
Update tests/includes/handler/class-test-create.php
pfefferle b05c85c
Fix typo in test method name
pfefferle d8de9a7
Whitespace changes
obenland fc945d2
Merge branch 'trunk' into add/inbox-visibility
pfefferle 58d0b5f
Keep parameter names aligned with hook docs
obenland 90d935a
Merge branch 'add/inbox-visibility' of https://github.com/Automattic/…
obenland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: changed | ||
|
||
Improved recipient handling for clarity and added better inbox support. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
/** | ||
* Audience Trait file. | ||
* | ||
* @package Activitypub | ||
*/ | ||
|
||
namespace Activitypub\Rest; | ||
|
||
use Activitypub\Collection\Actors; | ||
|
||
use function Activitypub\extract_recipients_from_activity; | ||
use function Activitypub\extract_recipients_from_activity_property; | ||
use function Activitypub\is_same_domain; | ||
use function Activitypub\user_can_activitypub; | ||
|
||
/** | ||
* Audience Trait. | ||
* | ||
* Provides methods for handling ActivityPub audience and recipient extraction. | ||
*/ | ||
trait Audience { | ||
pfefferle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
/** | ||
* Extract recipients from the given Activity. | ||
* | ||
* @param array $activity The activity data. | ||
* | ||
* @return array An array of user IDs who are the recipients of the activity. | ||
*/ | ||
public function determine_local_recipients( $activity ) { | ||
pfefferle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
$recipients = extract_recipients_from_activity( $activity ); | ||
$user_ids = array(); | ||
|
||
foreach ( $recipients as $recipient ) { | ||
|
||
if ( ! is_same_domain( $recipient ) ) { | ||
continue; | ||
} | ||
|
||
$user_id = Actors::get_id_by_resource( $recipient ); | ||
|
||
if ( \is_wp_error( $user_id ) ) { | ||
continue; | ||
} | ||
|
||
if ( ! user_can_activitypub( $user_id ) ) { | ||
continue; | ||
} | ||
|
||
$user_ids[] = $user_id; | ||
} | ||
|
||
return $user_ids; | ||
} | ||
|
||
/** | ||
* Determine the visibility of the activity based on its recipients. | ||
* | ||
* @param array $activity The activity data. | ||
* | ||
* @return string The visibility level: 'public', 'private', or 'direct'. | ||
*/ | ||
public function determine_visibility( $activity ) { | ||
pfefferle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
// Set default visibility for specific activity types. | ||
if ( in_array( $activity['type'], array( 'Accept', 'Delete', 'Follow', 'Reject', 'Undo' ), true ) ) { | ||
return ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE; | ||
} | ||
|
||
// Check 'to' field for public visibility. | ||
$to = extract_recipients_from_activity_property( 'to', $activity ); | ||
if ( ! empty( array_intersect( $to, ACTIVITYPUB_PUBLIC_AUDIENCE_IDENTIFIERS ) ) ) { | ||
return ACTIVITYPUB_CONTENT_VISIBILITY_PUBLIC; | ||
} | ||
|
||
// Check 'cc' field for quiet public visibility. | ||
$cc = extract_recipients_from_activity_property( 'cc', $activity ); | ||
if ( ! empty( array_intersect( $cc, ACTIVITYPUB_PUBLIC_AUDIENCE_IDENTIFIERS ) ) ) { | ||
return ACTIVITYPUB_CONTENT_VISIBILITY_QUIET_PUBLIC; | ||
} | ||
|
||
return ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.