Skip to:
Content

BuddyPress.org

Changeset 4367


Ignore:
Timestamp:
05/15/2011 10:40:03 PM (13 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

Location:
trunk
Files:
4 edited

Legend:

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

    r4305 r4367  
    113113 * @param string $content The activity content
    114114 */
    115 function bp_activity_at_name_filter( $content ) {
     115function bp_activity_at_name_filter( $activity ) {
     116    // Only run this function once for a given activity item
     117    remove_filter( 'bp_activity_after_save', 'bp_activity_at_name_filter' );
     118
     119    $content = $activity->content;
     120
    116121    $usernames = bp_activity_find_mentions( $content );
    117122
     
    126131
    127132        // Increase the number of new @ mentions for the user
    128         $new_mention_count = (int)get_user_meta( $user_id, 'bp_new_mention_count', true );
    129         update_user_meta( $user_id, 'bp_new_mention_count', $new_mention_count + 1 );
     133        bp_activity_adjust_mention_count( $activity->id, 'add' );
    130134
    131135        $content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $content );
    132136    }
    133137
    134     return $content;
     138    // Resave the activity item with the linked usernames
     139    $activity->content = $content;
     140    $activity->save();
    135141}
    136 add_filter( 'bp_activity_new_update_content',     'bp_activity_at_name_filter' );
    137 add_filter( 'groups_activity_new_update_content', 'bp_activity_at_name_filter' );
    138 add_filter( 'pre_comment_content',                'bp_activity_at_name_filter' );
    139 add_filter( 'group_forum_topic_text_before_save', 'bp_activity_at_name_filter' );
    140 add_filter( 'group_forum_post_text_before_save',  'bp_activity_at_name_filter' );
    141 add_filter( 'bp_activity_comment_content',        'bp_activity_at_name_filter' );
     142add_filter( 'bp_activity_after_save', 'bp_activity_at_name_filter' );
    142143
    143144function bp_activity_make_nofollow_filter( $text ) {
  • 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;
  • trunk/bp-activity/bp-activity-screens.php

    r4287 r4367  
    6868add_action( 'bp_activity_screen_single_activity_permalink', 'bp_activity_remove_screen_notifications' );
    6969add_action( 'bp_activity_screen_mentions',                  'bp_activity_remove_screen_notifications' );
     70
     71/**
     72 * Reset the logged-in user's new mentions data when he visits his mentions screen
     73 *
     74 * @package BuddyPress Activity
     75 * @since 1.3
     76 * @uses bp_activity_clear_new_mentions()
     77 * @uses bp_is_my_profile()
     78 */
     79function bp_activity_reset_my_new_mentions() { 
     80    if ( bp_is_my_profile() )
     81        bp_activity_clear_new_mentions( bp_loggedin_user_id() );
     82}
     83add_action( 'bp_activity_screen_mentions', 'bp_activity_reset_my_new_mentions' );
    7084
    7185function bp_activity_screen_single_activity_permalink() {
  • trunk/bp-themes/bp-default/_inc/ajax.php

    r4354 r4367  
    113113        case 'mentions':
    114114            $feed_url = $bp->loggedin_user->domain . bp_get_activity_slug() . '/mentions/feed/';
    115             delete_user_meta( $bp->loggedin_user->id, 'bp_new_mention_count' );
     115            bp_activity_clear_new_mentions( $bp->loggedin_user->id );
    116116            break;
    117117        default:
Note: See TracChangeset for help on using the changeset viewer.