Skip to:
Content

BuddyPress.org

Changeset 12223


Ignore:
Timestamp:
09/07/2018 01:54:05 PM (7 years ago)
Author:
djpaul
Message:

Notifications: clear activity notifications for replies to updates and comments.

Fixes #7907 (3.0 branch)

Props r-a-y

Location:
branches/3.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/src/bp-activity/bp-activity-notifications.php

    r12087 r12223  
    5656                $amount = 'multiple';
    5757            } else {
    58                 $link = add_query_arg( 'nid', (int) $id, bp_activity_get_permalink( $activity_id ) );
     58                $link = add_query_arg( 'rid', (int) $id, bp_activity_get_permalink( $activity_id ) );
    5959                $text = sprintf( __( '%1$s commented on one of your updates', 'buddypress' ), $user_fullname );
    6060            }
     
    7171                $amount = 'multiple';
    7272            } else {
    73                 $link = add_query_arg( 'nid', (int) $id, bp_activity_get_permalink( $activity_id ) );
    74                 $text = sprintf( __( '%1$s replied to one your activity comments', 'buddypress' ), $user_fullname );
     73                $link = add_query_arg( 'crid', (int) $id, bp_activity_get_permalink( $activity_id ) );
     74                $text = sprintf( __( '%1$s replied to one of your activity comments', 'buddypress' ), $user_fullname );
    7575            }
    7676        break;
     
    227227
    228228/**
    229  * Mark at-mention notification as read when user visits the activity with the mention.
     229 * Mark notifications as read when a user visits an activity permalink.
    230230 *
    231231 * @since 2.0.0
     232 * @since 3.2.0 Marks replies to parent update and replies to an activity comment as read.
    232233 *
    233234 * @param BP_Activity_Activity $activity Activity object.
     
    240241    // Mark as read any notifications for the current user related to this activity item.
    241242    bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), $activity->id, buddypress()->activity->id, 'new_at_mention' );
     243
     244    $comment_id = 0;
     245    // For replies to a parent update.
     246    if ( ! empty( $_GET['rid'] ) ) {
     247        $comment_id = (int) $_GET['rid'];
     248
     249    // For replies to an activity comment.
     250    } elseif ( ! empty( $_GET['crid'] ) ) {
     251        $comment_id = (int) $_GET['crid'];
     252    }
     253
     254    // Mark individual activity reply notification as read.
     255    if ( ! empty( $comment_id ) ) {
     256        BP_Notifications_Notification::update(
     257            array(
     258                'is_new' => false
     259            ),
     260            array(
     261                'user_id' => bp_loggedin_user_id(),
     262                'id'      => $comment_id
     263            )
     264        );
     265    }
    242266}
    243267add_action( 'bp_activity_screen_single_activity_permalink', 'bp_activity_remove_screen_notifications_single_activity_permalink' );
  • branches/3.0/tests/phpunit/testcases/activity/notifications.php

    r11882 r12223  
    365365        $expected_commenter = array( $u3 );
    366366        $this->assertEquals( $expected_commenter, wp_list_pluck( $u2_notifications, 'secondary_item_id' ) );
     367
     368        // Attempt to mark 'update_reply' notifications as read for user 1.
     369        foreach ( $u1_notifications as $i => $n ) {
     370            $n = bp_activity_format_notifications( $n->component_action, $n->item_id, $n->secondary_item_id, 1, 'array', $n->id );
     371            if ( ! empty( $n['link'] ) ) {
     372                // Remove redirecter for unit tests.
     373                $n['link'] = str_replace( '/p/', '/', $n['link'] );
     374
     375                // Attempt to clear the notification by going to the activity permalink.
     376                $this->go_to( $n['link'] );
     377            }
     378        }
     379
     380        // Assert that notifications for user 1 are cleared and empty.
     381        $this->assertEmpty( BP_Notifications_Notification::get( array(
     382            'user_id' => $this->u1,
     383        ) ) );
     384
     385        // Attempt to mark 'comment_reply' notifications as read for user 2.
     386        $this->set_current_user( $this->u2 );
     387        foreach ( $u2_notifications as $i => $n ) {
     388            $n = bp_activity_format_notifications( $n->component_action, $n->item_id, $n->secondary_item_id, 1, 'array', $n->id );
     389            if ( ! empty( $n['link'] ) ) {
     390                // Remove redirecter for unit tests.
     391                $n['link'] = str_replace( '/p/', '/', $n['link'] );
     392
     393                // Attempt to clear the notification by going to the activity permalink.
     394                $this->go_to( $n['link'] );
     395            }
     396        }
     397
     398        // Assert that notifications for user 2 are cleared and empty.
     399        $this->assertEmpty( BP_Notifications_Notification::get( array(
     400            'user_id' => $this->u2,
     401        ) ) );
    367402    }
    368403
Note: See TracChangeset for help on using the changeset viewer.