-
Notifications
You must be signed in to change notification settings - Fork 83
Fix false mention notifications for users in CC without mention tags #2532
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR addresses a bug where users were incorrectly receiving mention email notifications when they appeared in an activity's CC field but were not actually mentioned in the activity's tag array. The fix ensures that mention notifications are only sent when a user's actor ID is present in both the CC field and the activity's tag array with type: "Mention".
Key changes:
- Updated
Mailer::mention()to verify user actor IDs exist in activity tags before sending notifications - Added comprehensive test coverage for the bug fix and proper mention scenarios
- Includes substantial new Social Web admin interface infrastructure (TypeScript React application)
Reviewed changes
Copilot reviewed 87 out of 97 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| includes/class-mailer.php | Fixed mention notification logic to check tag array |
| tests/phpunit/tests/includes/class-test-mailer.php | Added tests for CC-only and proper mention scenarios |
| tests/phpunit/tests/includes/rest/class-test-actors-inbox-controller.php | Updated test with attributedTo field |
| tests/phpunit/tests/includes/handler/class-test-create.php | Updated test to use proper object structure |
| tests/phpunit/tests/includes/collection/class-test-posts.php | Updated test with content for excerpt generation |
| includes/handler/class-create.php | Removed conditional check for create_posts option |
| Multiple Social Web files | New TypeScript/React admin interface components |
Comments suppressed due to low confidence (2)
tests/phpunit/tests/includes/class-test-mailer.php:1
- The test assumes
Actors::get_by_id( $user_id )->get_id()will always succeed, but it could fail or return null. Consider adding validation or using a known valid actor ID to make the test more robust.
src/social-web/utils.ts:1 - Using
anytype defeats the purpose of TypeScript's type safety. These variables should be typed asnumbersince they are the result ofMath.floor().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
47d0359 to
bbbfea0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
includes/class-mailer.php
Outdated
| if ( \in_array( $actor_id, (array) $activity['cc'], true ) && isset( $activity['object']['tag'] ) ) { | ||
| foreach ( (array) $activity['object']['tag'] as $tag ) { | ||
| if ( object_to_uri( $tag ) === $actor_id ) { | ||
| $recipients[ $user_id ] = $actor_id; | ||
| break; | ||
| } | ||
| } | ||
| } |
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tag type should be explicitly checked to ensure it's a "Mention" before comparing the URI. Currently, any tag type with a matching href could trigger a notification. Consider adding a check like if ( isset( $tag['type'] ) && 'Mention' === $tag['type'] && object_to_uri( $tag ) === $actor_id ).
fb59436 to
6da5de1
Compare
|
It looks like sportsbots.xyz replaces the followers URL in This is the activity: https://browser.pub/https://sportsbots.xyz/users/FabrizioRomano/statuses/1993044518745334023 And this is what arrived in my inbox: {
"@context": [
"https://www.w3.org/ns/activitystreams",
{
"Hashtag": "as:Hashtag",
"sensitive": "as:sensitive",
"dcterms": "http://purl.org/dc/terms/",
"gts": "https://gotosocial.org/ns#",
"interactionPolicy": {
"@id": "gts:interactionPolicy",
"@type": "@id"
},
"canQuote": {
"@id": "gts:canQuote",
"@type": "@id"
},
"canReply": {
"@id": "gts:canReply",
"@type": "@id"
},
"canLike": {
"@id": "gts:canLike",
"@type": "@id"
},
"canAnnounce": {
"@id": "gts:canAnnounce",
"@type": "@id"
},
"automaticApproval": {
"@id": "gts:automaticApproval",
"@type": "@id"
},
"manualApproval": {
"@id": "gts:manualApproval",
"@type": "@id"
},
"always": {
"@id": "gts:always",
"@type": "@id"
}
}
],
"id": "https://sportsbots.xyz/users/FabrizioRomano/activities/1993044518745334023",
"type": "Create",
"published": "2025-11-24T19:50:16.000Z",
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"cc": [
"https://obietester.blog/?author=12082291"
],
"interactionPolicy": {
"canQuote": {
"automaticApproval": [
"https://www.w3.org/ns/activitystreams#Public"
]
}
},
"object": {
"id": "https://sportsbots.xyz/users/FabrizioRomano/statuses/1993044518745334023",
"type": "Note",
"attachment": [
{
"type": "Document",
"mediaType": "image/jpeg",
"url": "https://pbs.twimg.com/media/G6i3bLMW8AAUgoD.jpg",
"name": null,
"blurhash": "UMDlA{NxFz%2~WShOZW=58%0$4NG57$|wvs+",
"width": 1343,
"height": 1343
},
{
"type": "Document",
"mediaType": "image/jpeg",
"url": "https://pbs.twimg.com/media/G6i3bK9WIAA5Un4.jpg",
"name": null,
"blurhash": "UDC6DcJ~AA~BKh$kwOIqD%IoI[xbx^I.$x%f",
"width": 544,
"height": 544
}
],
"attributedTo": "https://sportsbots.xyz/users/FabrizioRomano",
"content": "<p>🚨 Hansi Flick: “I’m happy to have Rashford here at Barça. I’ve always been impressed by his quality and what he can do in the box, and he’s showing that in Barcelona”.</p><p>“New football, in Barcelona, with good weather… it’s incredible to see how he’s always smiling”.</p>",
"contentMap": {
"en": "<p>🚨 Hansi Flick: “I’m happy to have Rashford here at Barça. I’ve always been impressed by his quality and what he can do in the box, and he’s showing that in Barcelona”.</p><p>“New football, in Barcelona, with good weather… it’s incredible to see how he’s always smiling”.</p>"
},
"published": "2025-11-24T19:50:16.000Z",
"tag": [],
"url": "https://twitter.com/FabrizioRomano/status/1993044518745334023",
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"cc": [
"https://obietester.blog/?author=12082291"
],
"replies": {
"id": "https://sportsbots.xyz/replies/1993044518745334023",
"type": "Collection",
"first": "https://sportsbots.xyz/replies/1993044518745334023/1"
},
"sensitive": false,
"interactionPolicy": {
"canQuote": {
"automaticApproval": [
"https://www.w3.org/ns/activitystreams#Public"
]
}
}
},
"actor": "https://sportsbots.xyz/users/FabrizioRomano"
} |
Users were incorrectly receiving mention email notifications when they appeared in the CC field of an activity but were not actually mentioned in the content. This commonly occurred when users followed an actor and were added to CC for federation purposes. The fix verifies that a user's actor ID appears in the activity's tag array with type "Mention" before sending a mention notification, rather than just checking if they're in the CC field. Changes: - Add validation in Mailer::mention() to check for actual mention tags - Add object_to_uri() support for Mention type objects - Add test case for users in CC without mention tags (should not notify) - Add test case for users properly mentioned (should notify)
9b55ceb to
ae3ce13
Compare
|
Why is your blog in CC? |
|
No idea! 🙂 I assume sportsbots.xyz replaces the followers URL in |
Update mention logic to use 'object.tag' for mentions instead of 'cc' recipients. Simplifies recipient mapping by filtering and mapping mention tags.
…/Automattic/wordpress-activitypub into fix/mention-notification-cc-only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $mentions = wp_list_filter( (array) $activity['object']['tag'], array( 'type' => 'Mention' ) ); | ||
| $mentions = array_map( '\Activitypub\object_to_uri', $mentions ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| $mentions = wp_list_filter( (array) $activity['object']['tag'], array( 'type' => 'Mention' ) ); | |
| $mentions = array_map( '\Activitypub\object_to_uri', $mentions ); | |
| $mentions = \wp_list_filter( (array) $activity['object']['tag'], array( 'type' => 'Mention' ) ); | |
| $mentions = \array_map( '\Activitypub\object_to_uri', $mentions ); |
pfefferle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one!
Summary
Users were incorrectly receiving mention email notifications for activities where they appeared in the CC field but were not actually mentioned in the content. This commonly occurred when users followed an actor and were automatically added to CC for federation purposes.
For example, this activity would incorrectly trigger a mention notification even though the local user is not mentioned:
{ "actor": "https://sportsbots.xyz/users/NBA", "object": { "content": "<p>Join @NateDuncanNBA and @DannyLeroux...</p>", "tag": [ {"type": "Mention", "href": "https://twitter.com/NateDuncanNBA"}, {"type": "Mention", "href": "https://twitter.com/DannyLeroux"} ] }, "cc": ["https://obietester.blog/?author=12082291"] }The local user is in CC but not in the tags array, yet they were receiving a mention notification.
Proposed changes:
Mailer::mention()to verify that a user's actor ID appears in the activity'stagarray withtype: "Mention"before sending a mention notificationccfield, which was incorrect per ActivityPub semanticsOther information:
Testing instructions:
test_mention_requires_tag_not_just_ccverifies users in CC without mention tags don't receive notificationstest_mention_with_tag_sends_notificationverifies users properly mentioned do receive notificationsnpm run env-test -- --filter Test_MailerChangelog entry
Changelog Entry Details
Significance
Type
Message
False mention email notifications for users in CC field without actual mention tags.