Skip to:
Content

BuddyPress.org

Ticket #5328: 5328.03.diff

File 5328.03.diff, 22.4 KB (added by imath, 11 years ago)
  • bp-activity/bp-activity-classes.php

     
    11451145                                $filter_sql[] = $sid_sql;
    11461146                }
    11471147
     1148                if ( ! empty( $filter_array['id'] ) ) {
     1149                        $sid_sql = absint( $filter_array['id'] );
     1150                        $filter_sql[] = "a.id > {$sid_sql}";
     1151                }
     1152
    11481153                if ( empty( $filter_sql ) )
    11491154                        return false;
    11501155
  • bp-activity/bp-activity-filters.php

     
    396396
    397397        return apply_filters( 'bp_activity_truncate_entry', $excerpt, $text, $append_text );
    398398}
     399
     400/**
     401 * Include extra javascript dependencies for activity component.
     402 *
     403 * @since BuddyPress (2.0.0)
     404 *
     405 * @uses bp_activity_do_heartbeat() to check if heartbeat is required
     406 *
     407 * @param array $js_handles The original dependencies.
     408 * @return array $js_handles The new dependencies.
     409 */
     410function bp_activity_get_js_dependencies( $js_handles = array() ) {
     411        if ( bp_activity_do_heartbeat() ) {
     412                $js_handles[] = 'heartbeat';
     413        }
     414
     415        return $js_handles;
     416}
     417add_filter( 'bp_core_get_js_dependencies', 'bp_activity_get_js_dependencies', 10, 1 );
     418
     419/**
     420 * Adds a just-posted class to avoid some mess in activity ajax pagination
     421 *
     422 * @since  BuddyPress (2.0.0)
     423 * @param  string $classes
     424 * @return string $classes
     425 */
     426function bp_activity_newest_class( $classes = '' ) {
     427        $bp = buddypress();
     428       
     429        if (  ! empty( $bp->activity->new_update_id ) && $bp->activity->new_update_id == bp_get_activity_id() )
     430                $classes .= ' new-update';
     431       
     432        $classes .= ' just-posted';
     433        return $classes;
     434}
     435
     436/**
     437 * Uses WordPress Heartbeat API to check for latest activity update in BP Activity Admin screen
     438 *
     439 * @since BuddyPress (2.0.0)
     440 *
     441 * @uses  bp_activity_get_last_updated() to get the recorded date of the last activity
     442 * @param  array  $response
     443 * @param  array  $data
     444 * @return array  $response
     445 */
     446function bp_activity_heartbeat_last_recorded( $response = array(), $data = array() ) {
     447        $bp = buddypress();
     448
     449        if ( empty( $data['bp_activity_last_id'] ) )
     450                return $response;
     451
     452        $activity_latest_args = bp_parse_args(
     453                bp_ajax_querystring( 'activity' ),
     454                array( 'id' => absint( $data['bp_activity_last_id'] ) ),
     455                'activity_latest_args'
     456        );
     457
     458        $newest_activities = array();
     459        $last_activity_id = 0;
     460
     461        $last_updated = wp_cache_get( 'bp_activity_last_updated_id' , 'bp' );
     462
     463        if ( empty( $last_updated ) || ( is_array( $last_updated ) && $activity_latest_args != $last_updated['args'] ) ) {
     464                // temporarly adds a just_posted class for these activities
     465                add_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
     466               
     467                ob_start();
     468                if ( bp_has_activities ( $activity_latest_args ) ) {
     469
     470                        while ( bp_activities() ) {
     471                                bp_the_activity();
     472
     473                                if( $last_activity_id < bp_get_activity_id() )
     474                                        $last_activity_id = bp_get_activity_id();
     475
     476                                bp_get_template_part( 'activity/entry' );
     477                        }
     478
     479                }
     480                $newest_activities['activities'] = ob_get_contents();
     481                $newest_activities['last_id']    = $last_activity_id;
     482                ob_end_clean();
     483
     484                // remove the filter
     485                remove_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
     486
     487                if ( ! empty( $newest_activities['last_id'] ) ) {
     488                        $last_updated = array_merge( $newest_activities, array( 'args' => $activity_latest_args ) );
     489                        wp_cache_set( 'bp_activity_last_updated_id', $last_updated, 'bp' );
     490                }
     491        }
     492
     493        if ( ! empty( $last_updated ) )
     494                $response['bp_activity_newest_activities'] = array_diff_key( $last_updated, array( 'args' => $activity_latest_args ) );
     495
     496        return $response;
     497}
     498add_filter( 'heartbeat_received', 'bp_activity_heartbeat_last_recorded', 10, 2 );
     499add_filter( 'heartbeat_nopriv_received', 'bp_activity_heartbeat_last_recorded', 10, 2 );
     500
     501/**
     502 * Set the strings for WP HeartBeat API where needed
     503 *
     504 * @since  BuddyPress (2.0.0)
     505 *
     506 * @param  array  $strings localized strings
     507 * @return array  $strings
     508 */
     509function bp_activity_heartbeat_strings( $strings = array() ) {
     510
     511        if ( bp_activity_do_heartbeat() ) {
     512                $strings = array_merge( $strings, array(
     513                        'newest' => __( 'Load Newest', 'buddypress' ),
     514                        'pulse'  => apply_filters( 'bp_activity_heartbeat_pulse', 15 ),
     515                ) );
     516        }
     517
     518        return $strings;
     519}
     520add_filter( 'bp_core_get_js_strings', 'bp_activity_heartbeat_strings', 10, 1 );
  • bp-activity/bp-activity-functions.php

     
    11041104                BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id );
    11051105
    11061106        wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
     1107        wp_cache_delete( 'bp_activity_last_updated_id', 'bp' );
    11071108        do_action( 'bp_activity_add', $params );
    11081109
    11091110        return $activity->id;
     
    13541355        do_action( 'bp_activity_delete', $args );
    13551356        do_action( 'bp_activity_deleted_activities', $activity_ids_deleted );
    13561357
     1358        if ( $last_updated_id == wp_cache_get( 'bp_activity_last_updated_id' , 'bp' ) && in_array( $last_updated_id['last_id'], $activity_ids_deleted ) ) {
     1359                wp_cache_delete( 'bp_activity_last_updated_id', 'bp' );
     1360        }
     1361
    13571362        wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
    13581363
    13591364        return true;
     
    16601665        // Clear the activity comment cache for this activity item
    16611666        wp_cache_delete( 'bp_activity_comments_' . $activity->id, 'bp' );
    16621667
     1668        // Clear the last updated id if the spammed activity is the one that is cached
     1669        if ( $last_updated_id == wp_cache_get( 'bp_activity_last_updated_id' , 'bp' ) && $last_updated_id['last_id'] == $activity->id ) {
     1670                wp_cache_delete( 'bp_activity_last_updated_id', 'bp' );
     1671        }
     1672
    16631673        // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity
    16641674        if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) {
    16651675                remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 );
     
    17001710        // Clear the activity comment cache for this activity item
    17011711        wp_cache_delete( 'bp_activity_comments_' . $activity->id, 'bp' );
    17021712
     1713        // Clear the last updated id cache
     1714        wp_cache_delete( 'bp_activity_last_updated_id', 'bp' );
     1715
    17031716        // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity
    17041717        if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) {
    17051718                remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 );
     
    18491862function bp_embed_activity_save_cache( $cache, $cachekey, $id ) {
    18501863        bp_activity_update_meta( $id, $cachekey, $cache );
    18511864}
     1865
     1866
     1867/**
     1868 * Should we use HeartBeat to refresh activities every 15 s.
     1869 *
     1870 * @since BuddyPress (2.0.0)
     1871 *
     1872 * @uses bp_is_activity_heartbeat_active() to check if heatbeat setting is on
     1873 * @uses bp_is_activity_directory() to check if the current page is the activity directory
     1874 * @uses bp_is_active() to check if the group component is active
     1875 * @uses bp_is_group_activity() to check if on a single group, the current page is the group activities
     1876 * @uses bp_is_group_home() to check if the current page is a single group home page
     1877 * @return bool True on success, false on failure.
     1878 */
     1879function bp_activity_do_heartbeat() {
     1880        $retval = false;
     1881
     1882        if ( ! bp_is_activity_heartbeat_active() )
     1883                return $retval;
     1884
     1885        if ( bp_is_activity_directory() )
     1886                $retval = true;
     1887
     1888        if ( bp_is_active( 'groups') ) {
     1889                // If no custom front, then activities are loaded in group's home
     1890                $has_custom_front = bp_locate_template( array( 'groups/single/front.php' ), false, true );
     1891
     1892                if ( bp_is_group_activity() || ( ! $has_custom_front && bp_is_group_home() ) )
     1893                        $retval = true;
     1894        }
     1895
     1896        return $retval;
     1897}
  • bp-activity/bp-activity-template.php

     
    543543                'action'            => false,        // action to filter on e.g. activity_update, new_forum_post, profile_updated
    544544                'primary_id'        => $primary_id,  // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
    545545                'secondary_id'      => false,        // secondary object ID to filter on e.g. a post_id
     546                'id'                => false,        // activity id to get newer updates
    546547
    547548                'meta_query'        => false,        // filter on activity meta. See WP_Meta_Query for format
    548549
     
    561562                $display_comments = false;
    562563        }
    563564
     565        // reset pagination to get all new activities
     566        if ( ! empty( $id ) )
     567                $page = 0;
     568
    564569        if ( empty( $search_terms ) && ! empty( $_REQUEST['s'] ) )
    565570                $search_terms = $_REQUEST['s'];
    566571
     
    632637        // into bp-custom.php or your theme's functions.php
    633638        if ( isset( $_GET['afilter'] ) && apply_filters( 'bp_activity_enable_afilter_support', false ) )
    634639                $filter = array( 'object' => $_GET['afilter'] );
    635         else if ( !empty( $user_id ) || !empty( $object ) || !empty( $action ) || !empty( $primary_id ) || !empty( $secondary_id ) )
    636                 $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
     640        else if ( ! empty( $user_id ) || ! empty( $object ) || ! empty( $action ) || ! empty( $primary_id ) || ! empty( $secondary_id ) || ! empty( $id ) )
     641                $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id, 'id' => $id );
    637642        else
    638643                $filter = false;
    639644
     
    767772function bp_activity_has_more_items() {
    768773        global $activities_template;
    769774
    770         $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) );
     775        $remaining_pages = 0;
     776
     777        if ( ! empty( $activities_template->pag_page ) ) {
     778                $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) );
     779        }
     780
    771781        $has_more_items  = (int) $remaining_pages ? true : false;
    772782
    773783        return apply_filters( 'bp_activity_has_more_items', $has_more_items );
  • bp-core/admin/bp-core-settings.php

     
    104104}
    105105
    106106/**
     107 * Allow Heartbeat to refresh activity stream
     108 *
     109 * @since BuddyPress (2.0.0)
     110 */
     111function bp_admin_setting_callback_heartbeat() {
     112?>
     113
     114        <input id="_bp_enable_heartbeat_refresh" name="_bp_enable_heartbeat_refresh" type="checkbox" value="1" <?php checked( bp_is_activity_heartbeat_active( true ) ); ?> />
     115        <label for="_bp_enable_heartbeat_refresh"><?php _e( 'Allow activity stream to be refreshed every 15 seconds', 'buddypress' ); ?></label>
     116
     117<?php
     118}
     119
     120/**
    107121 * Sanitization for _bp_force_buddyvar
    108122 *
    109123 * If upgraded to 1.6 and you chose to keep the BuddyBar, a checkbox asks if you want to switch to
  • bp-core/bp-core-admin.php

     
    330330                        add_settings_field( 'bp-disable-blogforum-comments', __( 'Blog &amp; Forum Comments', 'buddypress' ), 'bp_admin_setting_callback_blogforum_comments', 'buddypress', 'bp_activity' );
    331331                        register_setting( 'buddypress', 'bp-disable-blogforum-comments', 'bp_admin_sanitize_callback_blogforum_comments' );
    332332
     333                        // Activity Heartbeat refresh
     334                        add_settings_field( '_bp_enable_heartbeat_refresh', __( 'Activity auto-refresh', 'buddypress' ), 'bp_admin_setting_callback_heartbeat', 'buddypress', 'bp_activity' );
     335                        register_setting( 'buddypress', '_bp_enable_heartbeat_refresh', 'intval' );
     336
    333337                        // Allow activity akismet
    334338                        if ( is_plugin_active( 'akismet/akismet.php' ) && defined( 'AKISMET_VERSION' ) ) {
    335339                                add_settings_field( '_bp_enable_akismet', __( 'Akismet',          'buddypress' ), 'bp_admin_setting_callback_activity_akismet', 'buddypress', 'bp_activity' );
  • bp-core/bp-core-functions.php

     
    18521852
    18531853        return $nav_item_url;
    18541854}
     1855
     1856/**
     1857 * Get the javascript dependencies for buddypress.js
     1858 *
     1859 * @since BuddyPress (2.0.0)
     1860 *
     1861 * @uses apply_filters() to allow other component to load extra dependencies
     1862 * @return array the javascript dependencies.
     1863 */
     1864function bp_core_get_js_dependencies() {
     1865        return apply_filters( 'bp_core_get_js_dependencies', array( 'jquery' ) );
     1866}
     1867
  • bp-core/bp-core-options.php

     
    586586}
    587587
    588588/**
     589 * Check whether Activity Heartbeat refresh is enabled.
     590 *
     591 * @since BuddyPress (2.0.0)
     592 *
     593 * @uses bp_get_option() To get the Heartbeat option.
     594 *
     595 * @param bool $default Optional. Fallback value if not found in the database.
     596 *        Default: true.
     597 * @return bool True if Heartbeat refresh is enabled, otherwise false.
     598 */
     599function bp_is_activity_heartbeat_active( $default = true ) {
     600        return (bool) apply_filters( 'bp_is_activity_heartbeat_active', (bool) bp_get_option( '_bp_enable_heartbeat_refresh', $default ) );
     601}
     602
     603/**
    589604 * Get the current theme package ID.
    590605 *
    591606 * @since BuddyPress (1.7.0)
  • bp-templates/bp-legacy/buddypress-functions.php

     
    223223                // Enqueue the global JS, if found - AJAX will not work
    224224                // without it
    225225                if ( isset( $asset['location'], $asset['handle'] ) ) {
    226                         wp_enqueue_script( $asset['handle'], $asset['location'], array( 'jquery' ), $this->version );
     226                        wp_enqueue_script( $asset['handle'], $asset['location'], bp_core_get_js_dependencies(), $this->version );
    227227                }
    228228
    229229                // Add words that we need to use in JS to the end of the page
    230230                // so they can be translated and still used.
    231                 $params = array(
     231                $params = apply_filters( 'bp_core_get_js_strings', array(
    232232                        'accepted'            => __( 'Accepted', 'buddypress' ),
    233233                        'close'               => __( 'Close', 'buddypress' ),
    234234                        'comments'            => __( 'comments', 'buddypress' ),
     
    242242                        'show_x_comments'     => __( 'Show all %d comments', 'buddypress' ),
    243243                        'unsaved_changes'     => __( 'Your profile has unsaved changes. If you leave the page, the changes will be lost.', 'buddypress' ),
    244244                        'view'                => __( 'View', 'buddypress' ),
    245                 );
     245                ) );
    246246                wp_localize_script( $asset['handle'], 'BP_DTheme', $params );
    247247
    248248                // Maybe enqueue comment reply JS
     
    480480                $qs[] = 'exclude=' . implode( ',', $just_posted );
    481481        }
    482482
     483        // to get newest activities
     484        if ( ! empty( $_POST['id'] ) )
     485                $qs[] = 'id=' . intval( $_POST['id'] );
     486
    483487        $object_search_text = bp_get_search_default_text( $object );
    484488        if ( ! empty( $_POST['search_terms'] ) && $object_search_text != $_POST['search_terms'] && 'false' != $_POST['search_terms'] && 'undefined' != $_POST['search_terms'] )
    485489                $qs[] = 'search_terms=' . $_POST['search_terms'];
     
    611615 * @since BuddyPress (1.2)
    612616 */
    613617function bp_legacy_theme_post_update() {
     618        $bp = buddypress();
     619
    614620        // Bail if not a POST action
    615621        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    616622                return;
     
    639645        if ( empty( $activity_id ) )
    640646                exit( '-1<div id="message" class="error"><p>' . __( 'There was a problem posting your update, please try again.', 'buddypress' ) . '</p></div>' );
    641647
    642         if ( bp_has_activities ( 'include=' . $activity_id ) ) {
     648        if ( ! empty( $_POST['id'] ) && $last_id = absint( $_POST['id'] ) ) {
     649                $activity_args = array( 'id' => $last_id );
     650                $bp->activity->new_update_id = $activity_id;
     651                add_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
     652        } else {
     653                $activity_args = array( 'include' => $activity_id );
     654        }
     655       
     656        if ( bp_has_activities ( $activity_args ) ) {
    643657                while ( bp_activities() ) {
    644658                        bp_the_activity();
    645659                        bp_get_template_part( 'activity/entry' );
    646660                }
    647661        }
    648662
     663        if ( ! empty( $last_id ) ) {
     664                remove_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
     665        }
     666       
    649667        exit;
    650668}
    651669
  • bp-templates/bp-legacy/css/buddypress.css

     
    290290        margin-left: 1em;
    291291        white-space: nowrap;
    292292}
    293 #buddypress .activity-list li.load-more {
     293#buddypress .activity-list li.load-more,
     294#buddypress .activity-list li.load-newest {
    294295        background: #f0f0f0;
    295296        font-size: 110%;
    296297        margin: 15px 0;
    297298        padding: 10px 15px;
    298299        text-align: center;
    299300}
    300 #buddypress .activity-list li.load-more a {
     301#buddypress .activity-list li.load-more a,
     302#buddypress .activity-list li.load-newest a {
    301303        color: #4D4D4D;
    302304}
    303305
  • bp-templates/bp-legacy/js/buddypress.js

     
    44// Global variable to prevent multiple AJAX requests
    55var bp_ajax_request = null;
    66
     7// Global variables to temporarly store newest activities
     8var newest_activities = '',
     9        activity_last_id  = 0;
     10
    711jq(document).ready( function() {
    812        /**** Page Load Actions *******************************************************/
    913
     
    5357                if ( $whats_new_form.hasClass("submitted") ) {
    5458                        $whats_new_form.removeClass("submitted");       
    5559                }
     60
     61                /* If the scope is not all, the activity update can temporarly be displayed
     62                   in the wrong tab which can be annoying with the load newest feature */
     63                if ( jq( '#activity-all' ).length  ) {
     64
     65                        if ( ! jq( '#activity-all' ).hasClass( 'selected' ) ) {
     66                                // reset to everyting
     67                                jq( '#activity-filter-select select' ).val( '-1' );
     68                                jq( '#activity-all a' ).trigger( "click" );
     69                        } else if ( '-1' != jq( '#activity-filter-select select' ).val() ) {
     70                                jq( '#activity-filter-select select' ).val( '-1' );
     71                                jq( '#activity-filter-select select' ).trigger( 'change' );
     72                        }
     73                }
    5674        });
    5775
    5876        /* On blur, shrink if it's empty */
     
    7189
    7290        /* New posts */
    7391        jq("#aw-whats-new-submit").on( 'click', function() {
    74                 var button = jq(this);
     92                var last_displayed_id = 0;
     93                var     button = jq(this);
    7594                var form = button.closest("form#whats-new-form");
    7695
    7796                form.children().each( function() {
     
    89108                var object = '';
    90109                var item_id = jq("#whats-new-post-in").val();
    91110                var content = jq("#whats-new").val();
     111                var firstrow = jq( '#buddypress ul.activity-list li' ).first();
    92112
     113                if ( firstrow.hasClass( 'load-newest' ) ) {
     114                        last_displayed_id = firstrow.next().prop( 'id' ) ? firstrow.next().prop( 'id' ).replace( 'activity-','' ) : 0;
     115                } else {
     116                        last_displayed_id = firstrow.prop( 'id' ) ? firstrow.prop( 'id' ).replace( 'activity-','' ) : 0;
     117                }
     118
    93119                /* Set object for non-profile posts */
    94120                if ( item_id > 0 ) {
    95121                        object = jq("#whats-new-post-object").val();
     
    102128                        'content': content,
    103129                        'object': object,
    104130                        'item_id': item_id,
     131                        'id': last_displayed_id,
    105132                        '_bp_as_nonce': jq('#_bp_as_nonce').val() || ''
    106133                },
    107134                function(response) {
     
    123150                                        jq("div.activity").append( '<ul id="activity-stream" class="activity-list item-list">' );
    124151                                }
    125152
     153                                if ( firstrow.hasClass( 'load-newest' ) )
     154                                        firstrow.remove();
     155
    126156                                jq("#activity-stream").prepend(response);
    127                                 jq("#activity-stream li:first").addClass('new-update just-posted');
    128157
     158                                if ( ! last_displayed_id )
     159                                        jq("#activity-stream li:first").addClass('new-update just-posted');
     160
    129161                                if ( 0 != jq("#latest-update").length ) {
    130162                                        var l = jq("#activity-stream li.new-update .activity-content .activity-inner p").html();
    131163                                        var v = jq("#activity-stream li.new-update .activity-content .activity-header p a.view").attr('href');
     
    351383
    352384                        return false;
    353385                }
     386
     387                /* Load newest updates at the top of the list */
     388                if ( target.parent().hasClass('load-newest') ) {
     389
     390                        event.preventDefault();
     391
     392                        target.parent().hide();
     393                        jq( '#buddypress ul.activity-list' ).prepend( newest_activities );
     394
     395                        // reset the newest activities now they're displayed
     396                        newest_activities = '';
     397                }
    354398        });
    355399
    356400        // Activity "Read More" links
     
    13451389        /* if js is enabled then replace the no-js class by a js one */
    13461390        if( jq('body').hasClass('no-js') )
    13471391                jq('body').attr('class', jq('body').attr('class').replace( /no-js/,'js' ) );
     1392
     1393
     1394        /** Activity HeartBeat ************************************************/
     1395
     1396        // Set the interval and the namespace event
     1397        if ( typeof wp.heartbeat != 'undefined' && typeof BP_DTheme.pulse != 'undefined' ) {
     1398
     1399                wp.heartbeat.interval( Number( BP_DTheme.pulse ) );
     1400
     1401                jq.fn.extend({
     1402                        'heartbeat-send': function() {
     1403                        return this.bind( 'heartbeat-send.buddypress' );
     1404                },
     1405            });
     1406
     1407        }
     1408       
     1409        // Set the last id to request after
     1410        jq( document ).on( 'heartbeat-send.buddypress', function( e, data ) {
     1411
     1412                // First row is default latest activity id
     1413                if ( jq( '#buddypress ul.activity-list li' ).first().prop( 'id' ) ) {
     1414                        firstrow = jq( '#buddypress ul.activity-list li' ).first().prop( 'id' ).replace( 'activity-','' );
     1415                } else {
     1416                        firstrow = 0;
     1417                }
     1418
     1419                if ( 0 == activity_last_id || Number( firstrow ) > activity_last_id )
     1420                        activity_last_id = Number( firstrow );
     1421
     1422                data['bp_activity_last_id'] = activity_last_id;
     1423    });
     1424
     1425        // Increment newest_activities and activity_last_id if data has been returned
     1426        jq( document ).on( 'heartbeat-tick', function( e, data ) {
     1427
     1428                // Only proceed if we have newest activities
     1429                if ( ! data['bp_activity_newest_activities'] )
     1430                return;
     1431
     1432        newest_activities = data['bp_activity_newest_activities']['activities'] + newest_activities;
     1433        activity_last_id  = Number( data['bp_activity_newest_activities']['last_id'] );
     1434
     1435        if ( jq( '#buddypress ul.activity-list li' ).first().hasClass( 'load-newest' ) )
     1436                        return;
     1437
     1438        jq( '#buddypress ul.activity-list' ).prepend( '<li class="load-newest"><a href="#newest">' + BP_DTheme.newest + '</a></li>' );
     1439
     1440    });
    13481441               
    13491442});
    13501443