diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php
index 2ca8d9f..cb550c7 100644
|
|
function bp_activity_find_mentions( $content ) { |
133 | 133 | function bp_activity_clear_new_mentions( $user_id ) { |
134 | 134 | bp_delete_user_meta( $user_id, 'bp_new_mention_count' ); |
135 | 135 | bp_delete_user_meta( $user_id, 'bp_new_mentions' ); |
| 136 | |
| 137 | /** |
| 138 | * Fires once mentions has been reset for a given user. |
| 139 | * |
| 140 | * @since 2.5.0 |
| 141 | * |
| 142 | * @param int $user_id The id of the user whose unread mentions are being reset. |
| 143 | */ |
| 144 | do_action( 'bp_activity_clear_new_mentions', $user_id ); |
136 | 145 | } |
137 | 146 | |
138 | 147 | /** |
diff --git src/bp-activity/bp-activity-notifications.php src/bp-activity/bp-activity-notifications.php
index 7fb5e92..beafe35 100644
|
|
add_action( 'bp_activity_sent_mention_email', 'bp_activity_at_mention_add_notifi |
499 | 499 | * Mark at-mention notifications as read when users visit their Mentions page. |
500 | 500 | * |
501 | 501 | * @since 1.5.0 |
| 502 | * @since 2.5.0 Add the $user_id parameter |
502 | 503 | * |
| 504 | * @param int $user_id The id of the user whose notifications are marked as read. |
503 | 505 | * @uses bp_notifications_mark_all_notifications_by_type() |
504 | 506 | */ |
505 | | function bp_activity_remove_screen_notifications() { |
| 507 | function bp_activity_remove_screen_notifications( $user_id = 0 ) { |
506 | 508 | if ( ! bp_is_active( 'notifications' ) ) { |
507 | 509 | return; |
508 | 510 | } |
509 | 511 | |
510 | | // Only mark read if you're looking at your own mentions. |
511 | | if ( ! bp_is_my_profile() ) { |
| 512 | // Only mark read if the current user is looking at his own mentions. |
| 513 | if ( empty( $user_id ) || (int) $user_id !== (int) bp_loggedin_user_id() ) { |
512 | 514 | return; |
513 | 515 | } |
514 | 516 | |
515 | | bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->activity->id, 'new_at_mention' ); |
| 517 | bp_notifications_mark_notifications_by_type( $user_id, buddypress()->activity->id, 'new_at_mention' ); |
516 | 518 | } |
517 | | add_action( 'bp_activity_screen_mentions', 'bp_activity_remove_screen_notifications' ); |
| 519 | add_action( 'bp_activity_clear_new_mentions', 'bp_activity_remove_screen_notifications', 10, 1 ); |
518 | 520 | |
519 | 521 | /** |
520 | 522 | * Mark at-mention notification as read when user visits the activity with the mention. |
diff --git tests/phpunit/testcases/activity/notifications.php tests/phpunit/testcases/activity/notifications.php
index 43d22f8..0604d0b 100644
|
|
class BP_Tests_Activity_Notifications extends BP_UnitTestCase { |
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
| 245 | * @group bp_activity_remove_screen_notifications |
| 246 | * @group mentions |
| 247 | * @ticket BP6687 |
| 248 | */ |
| 249 | public function test_bp_activity_remove_screen_notifications_on_new_mentions_cleared() { |
| 250 | $this->create_notifications(); |
| 251 | |
| 252 | $notifications = BP_Notifications_Notification::get( array( |
| 253 | 'item_id' => $this->a1, |
| 254 | ) ); |
| 255 | |
| 256 | // Double check it's there |
| 257 | $this->assertEquals( array( $this->a1 ), wp_list_pluck( $notifications, 'item_id' ) ); |
| 258 | $this->assertEquals( 1, bp_get_total_mention_count_for_user( $this->u1 ) ); |
| 259 | |
| 260 | // Clear notifications for $this->u1 |
| 261 | bp_activity_clear_new_mentions( $this->u1 ); |
| 262 | |
| 263 | $notifications = BP_Notifications_Notification::get( array( |
| 264 | 'item_id' => $this->a1, |
| 265 | ) ); |
| 266 | |
| 267 | $this->assertEmpty( $notifications, 'Notifications should be cleared when new mention metas are removed' ); |
| 268 | $this->assertEmpty( bp_get_total_mention_count_for_user( $this->u1 ) ); |
| 269 | } |
| 270 | |
| 271 | /** |
245 | 272 | * Creates two notifications for $u1, one of which is for mentions |
246 | 273 | */ |
247 | 274 | protected function create_notifications() { |