Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/08/2014 06:55:30 AM (13 years ago)
Author:
imath
Message:

Insert a new "since" filter for the activity stream to be used by HeartBeat check feature

In rare cases, the field date_recorded of the activity table can be updated to a date greater than the most recent activity in terms of id.
The Heartbeat feature was based on the id field so far, while the activity stream is sorting items according to the date_recorded field. As a result, in this very particular case, activities with an id greater than the activity (which date has been updated) will be loaded again in the stream and this until a new activity is published.
To prevent this to happen, we introduce this new "since" filter to be used by the HeartBeat feature once it gets the timestamp of the most recent activity displayed in the stream.

props SGr33n, boonebgorges, imath

Fixes #5505

File:
1 edited

Legend:

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

    r8219 r8251  
    430430        $bp = buddypress();
    431431
    432         if ( ! empty( $bp->activity->new_update_id ) && $bp->activity->new_update_id == bp_get_activity_id() ) {
     432        if ( ! empty( $bp->activity->last_recorded ) && $bp->activity->last_recorded == bp_get_activity_date_recorded() ) {
    433433                $classes .= ' new-update';
    434434        }
    … …  
    439439
    440440/**
     441 * Check if Activity Heartbeat feature i on to add a timestamp class.
     442 *
     443 * @since BuddyPress (2.0.0)
     444 *
     445 * @param string $classes
     446 * @return string $classes
     447 */
     448function bp_activity_timestamp_class( $classes = '' ) {
     449
     450        if ( ! bp_activity_do_heartbeat() ) {
     451                return $classes;
     452        }
     453
     454        $activity_date = bp_get_activity_date_recorded();
     455
     456        if ( empty( $activity_date ) ) {
     457                return $classes;
     458        }
     459       
     460        $classes .= ' date-recorded-' . strtotime( $activity_date );
     461
     462        return $classes;
     463}
     464add_filter( 'bp_get_activity_css_class', 'bp_activity_timestamp_class', 9, 1 );
     465
     466/**
    441467 * Use WordPress Heartbeat API to check for latest activity update.
    442468 *
    … …  
    444470 *
    445471 * @uses bp_activity_get_last_updated() to get the recorded date of the last activity
    446 
     472 *
    447473 * @param array $response
    448474 * @param array $data
    … …  
    452478        $bp = buddypress();
    453479
    454         if ( empty( $data['bp_activity_last_id'] ) ) {
     480        if ( empty( $data['bp_activity_last_recorded'] ) ) {
    455481                return $response;
    456482        }
    … …  
    460486        $activity_latest_args = bp_parse_args(
    461487                bp_ajax_querystring( 'activity' ),
    462                 array( 'offset' => absint( $data['bp_activity_last_id'] ) + 1 ),
     488                array( 'since' => date( 'Y-m-d H:i:s', $data['bp_activity_last_recorded'] ) ),
    463489                'activity_latest_args'
    464490        );
    465491
    466492        $newest_activities = array();
    467         $last_activity_id = 0;
     493        $last_activity_recorded = 0;
    468494
    469495        // Temporarly add a just-posted class for new activity items
    … …  
    475501                        bp_the_activity();
    476502
    477                         if ( $last_activity_id < bp_get_activity_id() ) {
    478                                 $last_activity_id = bp_get_activity_id();
     503                        $atime = strtotime( bp_get_activity_date_recorded() );
     504                        if ( $last_activity_recorded < $atime ) {
     505                                $last_activity_recorded = $atime;
    479506                        }
    480507
    … …  
    483510        }
    484511
    485         $newest_activities['activities'] = ob_get_contents();
    486         $newest_activities['last_id']    = $last_activity_id;
     512        $newest_activities['activities']    = ob_get_contents();
     513        $newest_activities['last_recorded'] = $last_activity_recorded;
    487514        ob_end_clean();
    488515
    … …  
    490517        remove_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
    491518
    492         if ( ! empty( $newest_activities['last_id'] ) ) {
     519        if ( ! empty( $newest_activities['last_recorded'] ) ) {
    493520                $response['bp_activity_newest_activities'] = $newest_activities;
    494521        }
Note: See TracChangeset for help on using the changeset viewer.