Skip to:
Content

BuddyPress.org

Ticket #5505: 5505.patch

File 5505.patch, 6.4 KB (added by boonebgorges, 11 years ago)
  • bp-activity/bp-activity-classes.php

    diff --git bp-activity/bp-activity-classes.php bp-activity/bp-activity-classes.php
    index a210786..f18b6b9 100644
    class BP_Activity_Activity { 
    11771177         * @since BuddyPress (1.5.0)
    11781178         *
    11791179         * @param array $filter_array {
    1180          *     Fields and values to filter by. Each can be either a single
    1181          *     string, a comma-separated list, or an array of values.
     1180         *     Fields and values to filter by.
    11821181         *     @type array|string|id $user_id User ID(s).
    11831182         *     @type array|string $object Corresponds to the 'component'
    11841183         *           column in the database.
    class BP_Activity_Activity { 
    11881187         *           column in the database.
    11891188         *     @type array|string|int $secondary_id Corresponds to the
    11901189         *           'secondary_item_id' column in the database.
     1190         *     @type int $offset Return only those items with an ID greater
     1191         *           than the offset value.
     1192         *     @type string $since Return only those items that have a
     1193         *           date_recorded value greater than a given MySQL-formatted
     1194         *           date.
    11911195         * }
    11921196         * @return string The filter clause, for use in a SQL query.
    11931197         */
    class BP_Activity_Activity { 
    12301234                        $filter_sql[] = "a.id >= {$sid_sql}";
    12311235                }
    12321236
     1237                if ( ! empty( $filter_array['since'] ) ) {
     1238                        // Validate that this is a proper Y-m-d H:i:s date
     1239                        // Trick: parse to UNIX date then translate back
     1240                        $translated_date = date( 'Y-m-d H:i:s', strtotime( $filter_array['since'] ) );
     1241                        if ( $translated_date === $filter_array['since'] ) {
     1242                                $filter_sql[] = "a.date_recorded > '{$translated_date}'";
     1243                        }
     1244                }
     1245
    12331246                if ( empty( $filter_sql ) )
    12341247                        return false;
    12351248
  • bp-activity/bp-activity-filters.php

    diff --git bp-activity/bp-activity-filters.php bp-activity/bp-activity-filters.php
    index 8f9cbff..fab4bfc 100644
    function bp_activity_newest_class( $classes = '' ) { 
    451451function bp_activity_heartbeat_last_recorded( $response = array(), $data = array() ) {
    452452        $bp = buddypress();
    453453
    454         if ( empty( $data['bp_activity_last_id'] ) ) {
     454        if ( empty( $data['bp_activity_last_recorded'] ) ) {
    455455                return $response;
    456456        }
    457457
    function bp_activity_heartbeat_last_recorded( $response = array(), $data = array 
    459459        // filters), but force the offset to get only new items
    460460        $activity_latest_args = bp_parse_args(
    461461                bp_ajax_querystring( 'activity' ),
    462                 array( 'offset' => absint( $data['bp_activity_last_id'] ) + 1 ),
     462                array( 'since' => date( 'Y-m-d H:i:s', $data['bp_activity_last_recorded'] ) ),
    463463                'activity_latest_args'
    464464        );
    465465
    466466        $newest_activities = array();
    467         $last_activity_id = 0;
     467        $last_activity_recorded = 0;
    468468
    469469        // Temporarly add a just-posted class for new activity items
    470470        add_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
    function bp_activity_heartbeat_last_recorded( $response = array(), $data = array 
    474474                while ( bp_activities() ) {
    475475                        bp_the_activity();
    476476
    477                         if ( $last_activity_id < bp_get_activity_id() ) {
    478                                 $last_activity_id = bp_get_activity_id();
     477                        $atime = strtotime( bp_get_activity_date_recorded() );
     478                        if ( $last_activity_recorded < $atime ) {
     479                                $last_activity_recorded = $atime;
    479480                        }
    480481
    481482                        bp_get_template_part( 'activity/entry' );
    482483                }
    483484        }
    484485
    485         $newest_activities['activities'] = ob_get_contents();
    486         $newest_activities['last_id']    = $last_activity_id;
     486        $newest_activities['activities']    = ob_get_contents();
     487        $newest_activities['last_recorded'] = $last_activity_recorded;
    487488        ob_end_clean();
    488489
    489490        // Remove the temporary filter
  • bp-activity/bp-activity-template.php

    diff --git bp-activity/bp-activity-template.php bp-activity/bp-activity-template.php
    index e6b57dd..96395d3 100644
    function bp_has_activities( $args = '' ) { 
    547547                'primary_id'        => $primary_id,  // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
    548548                'secondary_id'      => false,        // secondary object ID to filter on e.g. a post_id
    549549                'offset'            => false,        // return only items >= this ID
     550                'since'             => false,        // return only items recorded since this Y-m-d H:i:s date
    550551
    551552                'meta_query'        => false,        // filter on activity meta. See WP_Meta_Query for format
    552553
    function bp_send_public_message_link() { 
    28052806 */
    28062807function bp_activity_recurse_comments_activity_ids( $activity = array(), $activity_ids = array() ) {
    28072808        if ( is_array( $activity ) && ! empty( $activity['activities'] ) ) {
    2808                 $activity = $activity['activities'][0]; 
     2809                $activity = $activity['activities'][0];
    28092810        }
    28102811
    28112812        if ( ! empty( $activity->children ) ) {
  • bp-templates/bp-legacy/js/buddypress.js

    diff --git bp-templates/bp-legacy/js/buddypress.js bp-templates/bp-legacy/js/buddypress.js
    index 610f704..578eb16 100644
    jq(document).ready( function() { 
    15081508
    15091509        // Increment newest_activities and activity_last_id if data has been returned
    15101510        jq( document ).on( 'heartbeat-tick', function( e, data ) {
     1511                console.log(data);
    15111512
    15121513                // Only proceed if we have newest activities
    15131514                if ( ! data['bp_activity_newest_activities'] ) {
  • tests/testcases/activity/class.BP_Activity_Activity.php

    diff --git tests/testcases/activity/class.BP_Activity_Activity.php tests/testcases/activity/class.BP_Activity_Activity.php
    index 4b0744a..f8eaa8b 100644
    class BP_Tests_Activity_Class extends BP_UnitTestCase { 
    282282                $ids = wp_list_pluck( $activity['activities'], 'id' );
    283283                $this->assertEquals( array( $a3, $a2 ), $ids );
    284284        }
     285
     286        /**
     287         * @group get
     288         */
     289        public function test_get_with_since() {
     290                $now = time();
     291                $a1 = $this->factory->activity->create( array(
     292                        'content' => 'Life Rules',
     293                        'recorded_time' => date( 'Y-m-d H:i:s', $now - 100 ),
     294                ) );
     295                $a2 = $this->factory->activity->create( array(
     296                        'content' => 'Life Drools',
     297                        'recorded_time' => date( 'Y-m-d H:i:s', $now - 50 ),
     298                ) );
     299                $a3 = $this->factory->activity->create( array(
     300                        'content' => 'Life Drools',
     301                        'recorded_time' => date( 'Y-m-d H:i:s', $now - 10 ),
     302                ) );
     303
     304                $activity = BP_Activity_Activity::get( array(
     305                        'filter' => array(
     306                                'since' => date( 'Y-m-d H:i:s', $now - 70 ),
     307                        ),
     308                ) );
     309                $ids = wp_list_pluck( $activity['activities'], 'id' );
     310                $this->assertEquals( array( $a3, $a2 ), $ids );
     311        }
     312
    285313        /**
    286314         * @group get_id
    287315         */