Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/21/2014 02:49:33 PM (12 years ago)
Author:
boonebgorges
Message:

Automatically check for newly created items when viewing the Activity Stream.

Leveraging WP's Heartbeat API, this new functionality performs periodic checks
to see whether new activity items matching the current filter have been posted
since the page was originally loaded. If new items are found, a Load Newest
link is inserted into the top of the stream, which will insert the new items.

A filter is included, bp_activity_heartbeat_pulse, that allows site owners to
set a specific interval for these checks. The default value is 15 seconds, or
whatever your global Heartbeat interval is.

To disable the feature, there is a new setting "Automatically check for new
activity items when viewing the activity stream".

Fixes #5328

Props imath, boonebgorges

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-templates/bp-legacy/buddypress-functions.php

    r7949 r7952  
    226226        // without it
    227227        if ( isset( $asset['location'], $asset['handle'] ) ) {
    228             wp_enqueue_script( $asset['handle'], $asset['location'], array( 'jquery' ), $this->version );
     228            wp_enqueue_script( $asset['handle'], $asset['location'], bp_core_get_js_dependencies(), $this->version );
    229229        }
    230230
    231231        // Add words that we need to use in JS to the end of the page
    232232        // so they can be translated and still used.
    233         $params = array(
     233        $params = apply_filters( 'bp_core_get_js_strings', array(
    234234            'accepted'            => __( 'Accepted', 'buddypress' ),
    235235            'close'               => __( 'Close', 'buddypress' ),
     
    245245            'unsaved_changes'     => __( 'Your profile has unsaved changes. If you leave the page, the changes will be lost.', 'buddypress' ),
    246246            'view'                => __( 'View', 'buddypress' ),
    247         );
     247        ) );
    248248        wp_localize_script( $asset['handle'], 'BP_DTheme', $params );
    249249
     
    510510        $just_posted = wp_parse_id_list( $_POST['exclude_just_posted'] );
    511511        $qs[] = 'exclude=' . implode( ',', $just_posted );
     512    }
     513
     514    // to get newest activities
     515    if ( ! empty( $_POST['offset'] ) ) {
     516        $qs[] = 'offset=' . intval( $_POST['offset'] );
    512517    }
    513518
     
    650655 */
    651656function bp_legacy_theme_post_update() {
     657    $bp = buddypress();
     658
    652659    // Bail if not a POST action
    653660    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     
    678685        exit( '-1<div id="message" class="error"><p>' . __( 'There was a problem posting your update, please try again.', 'buddypress' ) . '</p></div>' );
    679686
    680     if ( bp_has_activities ( 'include=' . $activity_id ) ) {
     687    if ( ! empty( $_POST['offset'] ) && $last_id = absint( $_POST['offset'] ) ) {
     688        $activity_args = array( 'offset' => $last_id );
     689        $bp->activity->new_update_id = $activity_id;
     690        add_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
     691    } else {
     692        $activity_args = array( 'include' => $activity_id );
     693    }
     694
     695    if ( bp_has_activities ( $activity_args ) ) {
    681696        while ( bp_activities() ) {
    682697            bp_the_activity();
    683698            bp_get_template_part( 'activity/entry' );
    684699        }
     700    }
     701
     702    if ( ! empty( $last_id ) ) {
     703        remove_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
    685704    }
    686705
Note: See TracChangeset for help on using the changeset viewer.