Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
05/15/2011 10:40:03 PM (11 years ago)
Author:
boonebgorges
Message:

Reconfigures the way that new activity mentions are stored and incremented, so that counts more accurately reflect new and deleted activity items. Fixes #2082

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-functions.php

    r4277 r4367  
    1616 * @since 1.3
    1717 *
    18  * @param $content The content of the activity, usually found in $activity->content
     18 * @param str $content The content of the activity, usually found in $activity->content
    1919 * @return array $usernames Array of the found usernames that match existing users
    2020 */
     
    3131
    3232/**
    33  * Reduces new mention count for mentioned users when activity items are deleted
     33 * Resets a user's unread mentions list and count
    3434 *
    3535 * @package BuddyPress Activity
    3636 * @since 1.3
    3737 *
    38  * @param $activity_id The unique id for the activity item
    39  */
    40 function bp_activity_reduce_mention_count( $activity_id ) {
     38 * @param int $user_id The id of the user whose unread mentions are being reset
     39 */
     40function bp_activity_clear_new_mentions( $user_id ) {
     41    delete_user_meta( $user_id, 'bp_new_mention_count' );
     42    delete_user_meta( $user_id, 'bp_new_mentions' );
     43}
     44
     45/**
     46 * Adjusts new mention count for mentioned users when activity items are deleted or created
     47 *
     48 * @package BuddyPress Activity
     49 * @since 1.3
     50 *
     51 * @param int $activity_id The unique id for the activity item
     52 */
     53function bp_activity_adjust_mention_count( $activity_id, $action = 'add' ) {
    4154    $activity = new BP_Activity_Activity( $activity_id );
    4255
     
    5164                continue;
    5265
    53             // Decrease the number of new @ mentions for the user
     66            // Adjust the mention list and count for the member
    5467            $new_mention_count = (int)get_user_meta( $user_id, 'bp_new_mention_count', true );
    55             update_user_meta( $user_id, 'bp_new_mention_count', $new_mention_count - 1 );
     68            if ( !$new_mentions = get_user_meta( $user_id, 'bp_new_mentions', true ) )
     69                $new_mentions = array();
     70               
     71            switch ( $action ) {
     72                case 'delete' :
     73                    $key = array_search( $activity_id, $new_mentions );
     74                    if ( $key !== false ) {
     75                        var_dump( $new_mentions );
     76                        var_dump( $activity_id );
     77                        unset( $new_mentions[$key] );
     78                    }
     79                    break;
     80               
     81                case 'add' :
     82                default :
     83                    if ( !in_array( $activity_id, $new_mentions ) ) {
     84                        $new_mentions[] = (int)$activity_id;
     85                    }
     86                    break;
     87            }
     88           
     89            // Get an updated mention count         
     90            $new_mention_count = count( $new_mentions );
     91           
     92            // Resave the user_meta
     93            update_user_meta( $user_id, 'bp_new_mention_count', $new_mention_count );
     94            update_user_meta( $user_id, 'bp_new_mentions', $new_mentions );
    5695        }
    5796    }
    5897}
    59 add_action( 'bp_activity_action_delete_activity', 'bp_activity_reduce_mention_count' );
    6098
    6199/**
     
    758796    $args = wp_parse_args( $args, $defaults );
    759797
     798    // Adjust the new mention count of any mentioned member
     799    bp_activity_adjust_mention_count( $args['id'], 'delete' );
     800
    760801    if ( !$activity_ids_deleted = BP_Activity_Activity::delete( $args ) )
    761802        return false;
Note: See TracChangeset for help on using the changeset viewer.