Skip to:
Content

BuddyPress.org

Ticket #7135: 7135.02.patch

File 7135.02.patch, 7.2 KB (added by r-a-y, 8 years ago)
  • src/bp-activity/bp-activity-functions.php

     
    30303030                $link = $activity_obj->primary_link;
    30313031        } else {
    30323032                if ( 'activity_comment' == $activity_obj->type ) {
    3033                         $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->item_id . '/';
     3033                        $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->item_id . '/#acomment-' . $activity_obj->id;
    30343034                } else {
    30353035                        $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->id . '/';
    30363036                }
  • src/bp-activity/bp-activity-notifications.php

     
    208208 * @param int    $secondary_item_id In the case of at-mentions, this is the mentioner's ID.
    209209 * @param int    $total_items       The total number of notifications to format.
    210210 * @param string $format            'string' to get a BuddyBar-compatible notification, 'array' otherwise.
     211 * @param int    $id                The notification ID.
    211212 * @return string $return Formatted @mention notification.
    212213 */
    213 function bp_activity_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
     214function bp_activity_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string', $id ) {
    214215        $action_filter = $action;
    215216        $return        = false;
    216217        $activity_id   = $item_id;
     
    225226                        $amount        = 'single';
    226227
    227228                        if ( (int) $total_items > 1 ) {
    228                                 $text = sprintf( __( 'You have %1$d new mentions', 'buddypress' ), (int) $total_items );
     229                                $text   = sprintf( __( 'You have %1$d new mentions', 'buddypress' ), (int) $total_items );
    229230                                $amount = 'multiple';
    230231                        } else {
    231                                 $text =  sprintf( __( '%1$s mentioned you', 'buddypress' ), $user_fullname );
     232                                $text = sprintf( __( '%1$s mentioned you', 'buddypress' ), $user_fullname );
    232233                        }
    233234                break;
    234235
     
    242243                                $text   = sprintf( __( 'You have %1$d new replies', 'buddypress' ), (int) $total_items );
    243244                                $amount = 'multiple';
    244245                        } else {
    245                                 $link   = bp_activity_get_permalink( $activity_id );
    246                                 $text   = sprintf( __( '%1$s commented on one of your updates', 'buddypress' ), $user_fullname );
     246                                $link = add_query_arg( 'nid', $id, bp_activity_get_permalink( $activity_id ) );
     247                                $text = sprintf( __( '%1$s commented on one of your updates', 'buddypress' ), $user_fullname );
    247248                        }
    248249                break;
    249250
     
    257258                                $text   = sprintf( __( 'You have %1$d new comment replies', 'buddypress' ), (int) $total_items );
    258259                                $amount = 'multiple';
    259260                        } else {
    260                                 $link   = bp_activity_get_permalink( $activity_id );
    261                                 $text   = sprintf( __( '%1$s replied to one your activity comments', 'buddypress' ), $user_fullname );
     261                                $link = add_query_arg( 'nid', $id, bp_activity_get_permalink( $activity_id ) );
     262                                $text = sprintf( __( '%1$s replied to one your activity comments', 'buddypress' ), $user_fullname );
    262263                        }
    263264                break;
    264265        }
     
    365366        if ( bp_is_active( 'notifications' ) ) {
    366367                bp_notifications_add_notification( array(
    367368                        'user_id'           => $activity->user_id,
    368                         'item_id'           => $activity->id,
     369                        'item_id'           => $comment_id,
    369370                        'secondary_item_id' => $commenter_id,
    370371                        'component_name'    => buddypress()->activity->id,
    371372                        'component_action'  => 'update_reply',
     
    389390        if ( bp_is_active( 'notifications' ) ) {
    390391                bp_notifications_add_notification( array(
    391392                        'user_id'           => $activity_comment->user_id,
    392                         'item_id'           => $activity_comment->item_id,
     393                        'item_id'           => $comment_id,
    393394                        'secondary_item_id' => $commenter_id,
    394395                        'component_name'    => buddypress()->activity->id,
    395396                        'component_action'  => 'comment_reply',
     
    426427 * Mark at-mention notification as read when user visits the activity with the mention.
    427428 *
    428429 * @since 2.0.0
    429  * @since 2.6.0 Mark notifications for 'update_reply' and 'comment_reply' actions
    430430 *
    431431 * @param BP_Activity_Activity $activity Activity object.
    432432 */
     
    439439                return;
    440440        }
    441441
    442         /**
    443          * Filter here to add the notification actions to mark as read
    444          * when the single activity is displayed.
    445          *
    446          * @since 2.6.0
    447          *
    448          * @param array $value List of notification actions to mark as read.
    449          */
    450         $notification_actions = apply_filters( 'bp_activity_notification_actions_single_activity', array(
    451                 'new_at_mention',
    452                 'update_reply',
    453                 'comment_reply',
    454         ) );
    455 
    456         $user_id   = bp_loggedin_user_id();
    457         $component = buddypress()->activity->id;
    458 
    459         foreach ( $notification_actions as $action ) {
    460                 // Mark as read any notifications for the current user related to this activity item.
    461                 bp_notifications_mark_notifications_by_item_id( $user_id, $activity->id, $component, $action );
    462         }
     442        // Mark as read any notifications for the current user related to this activity item.
     443        bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), $activity->id, buddypress()->activity->id, 'new_at_mention' );
    463444}
    464445add_action( 'bp_activity_screen_single_activity_permalink', 'bp_activity_remove_screen_notifications_single_activity_permalink' );
    465446
    466447/**
     448 * Mark non-mention notifications as read when user visits our read permalink.
     449 *
     450 * In particular, 'update_reply' and 'comment_reply' notifications are handled
     451 * here. See {@link bp_activity_format_notifications()} for more info.
     452 *
     453 * @since 2.6.0
     454 */
     455function bp_activity_remove_screen_notifications_for_non_mentions() {
     456        if ( false === bp_is_active( 'notifications' ) || false === is_singular() || false === is_user_logged_in() || empty( $_GET['nid'] ) ) {
     457                return;
     458        }
     459
     460        // Mark notification as read.
     461        BP_Notifications_Notification::update(
     462                array(
     463                        'is_new'  => false
     464                ),
     465                array(
     466                        'user_id' => bp_loggedin_user_id(),
     467                        'id'      => $_GET['nid']
     468                )
     469        );
     470}
     471add_action( 'bp_screens', 'bp_activity_remove_screen_notifications_for_non_mentions' );
     472
     473/**
    467474 * Delete at-mention notifications when the corresponding activity item is deleted.
    468475 *
    469476 * @since 2.0.0
  • src/bp-activity/bp-activity-template.php

     
    24202420         *
    24212421         * @since 1.8.0
    24222422         *
    2423          *
    24242423         * @return string $link The activity comment permalink.
    24252424         */
    24262425        function bp_get_activity_comment_permalink() {
    24272426                global $activities_template;
    24282427
    2429                 // Check that comment exists.
     2428                $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity );
     2429
     2430                // Used for filter below.
    24302431                $comment_id = isset( $activities_template->activity->current_comment->id )
    24312432                        ? $activities_template->activity->current_comment->id
    24322433                        : 0;
    24332434
    2434                 // Setup the comment link.
    2435                 $comment_link = ! empty( $comment_id )
    2436                         ? '#acomment-' .$comment_id
    2437                         : false;
    2438 
    2439                 // Append comment ID to end of activity permalink.
    2440                 $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ) . $comment_link;
    2441 
    24422435                /**
    24432436                 * Filters the activity comment permalink.
    24442437                 *