diff --git bp-activity/bp-activity-classes.php bp-activity/bp-activity-classes.php
index a210786..f18b6b9 100644
|
|
class BP_Activity_Activity { |
1177 | 1177 | * @since BuddyPress (1.5.0) |
1178 | 1178 | * |
1179 | 1179 | * @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. |
1182 | 1181 | * @type array|string|id $user_id User ID(s). |
1183 | 1182 | * @type array|string $object Corresponds to the 'component' |
1184 | 1183 | * column in the database. |
… |
… |
class BP_Activity_Activity { |
1188 | 1187 | * column in the database. |
1189 | 1188 | * @type array|string|int $secondary_id Corresponds to the |
1190 | 1189 | * '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. |
1191 | 1195 | * } |
1192 | 1196 | * @return string The filter clause, for use in a SQL query. |
1193 | 1197 | */ |
… |
… |
class BP_Activity_Activity { |
1230 | 1234 | $filter_sql[] = "a.id >= {$sid_sql}"; |
1231 | 1235 | } |
1232 | 1236 | |
| 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 | |
1233 | 1246 | if ( empty( $filter_sql ) ) |
1234 | 1247 | return false; |
1235 | 1248 | |
diff --git bp-activity/bp-activity-filters.php bp-activity/bp-activity-filters.php
index 8f9cbff..fab4bfc 100644
|
|
function bp_activity_newest_class( $classes = '' ) { |
451 | 451 | function bp_activity_heartbeat_last_recorded( $response = array(), $data = array() ) { |
452 | 452 | $bp = buddypress(); |
453 | 453 | |
454 | | if ( empty( $data['bp_activity_last_id'] ) ) { |
| 454 | if ( empty( $data['bp_activity_last_recorded'] ) ) { |
455 | 455 | return $response; |
456 | 456 | } |
457 | 457 | |
… |
… |
function bp_activity_heartbeat_last_recorded( $response = array(), $data = array |
459 | 459 | // filters), but force the offset to get only new items |
460 | 460 | $activity_latest_args = bp_parse_args( |
461 | 461 | 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'] ) ), |
463 | 463 | 'activity_latest_args' |
464 | 464 | ); |
465 | 465 | |
466 | 466 | $newest_activities = array(); |
467 | | $last_activity_id = 0; |
| 467 | $last_activity_recorded = 0; |
468 | 468 | |
469 | 469 | // Temporarly add a just-posted class for new activity items |
470 | 470 | add_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 ); |
… |
… |
function bp_activity_heartbeat_last_recorded( $response = array(), $data = array |
474 | 474 | while ( bp_activities() ) { |
475 | 475 | bp_the_activity(); |
476 | 476 | |
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; |
479 | 480 | } |
480 | 481 | |
481 | 482 | bp_get_template_part( 'activity/entry' ); |
482 | 483 | } |
483 | 484 | } |
484 | 485 | |
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; |
487 | 488 | ob_end_clean(); |
488 | 489 | |
489 | 490 | // Remove the temporary filter |
diff --git bp-activity/bp-activity-template.php bp-activity/bp-activity-template.php
index e6b57dd..96395d3 100644
|
|
function bp_has_activities( $args = '' ) { |
547 | 547 | 'primary_id' => $primary_id, // object ID to filter on e.g. a group_id or forum_id or blog_id etc. |
548 | 548 | 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id |
549 | 549 | 'offset' => false, // return only items >= this ID |
| 550 | 'since' => false, // return only items recorded since this Y-m-d H:i:s date |
550 | 551 | |
551 | 552 | 'meta_query' => false, // filter on activity meta. See WP_Meta_Query for format |
552 | 553 | |
… |
… |
function bp_send_public_message_link() { |
2805 | 2806 | */ |
2806 | 2807 | function bp_activity_recurse_comments_activity_ids( $activity = array(), $activity_ids = array() ) { |
2807 | 2808 | if ( is_array( $activity ) && ! empty( $activity['activities'] ) ) { |
2808 | | $activity = $activity['activities'][0]; |
| 2809 | $activity = $activity['activities'][0]; |
2809 | 2810 | } |
2810 | 2811 | |
2811 | 2812 | if ( ! empty( $activity->children ) ) { |
diff --git bp-templates/bp-legacy/js/buddypress.js bp-templates/bp-legacy/js/buddypress.js
index 610f704..578eb16 100644
|
|
jq(document).ready( function() { |
1508 | 1508 | |
1509 | 1509 | // Increment newest_activities and activity_last_id if data has been returned |
1510 | 1510 | jq( document ).on( 'heartbeat-tick', function( e, data ) { |
| 1511 | console.log(data); |
1511 | 1512 | |
1512 | 1513 | // Only proceed if we have newest activities |
1513 | 1514 | if ( ! data['bp_activity_newest_activities'] ) { |
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 { |
282 | 282 | $ids = wp_list_pluck( $activity['activities'], 'id' ); |
283 | 283 | $this->assertEquals( array( $a3, $a2 ), $ids ); |
284 | 284 | } |
| 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 | |
285 | 313 | /** |
286 | 314 | * @group get_id |
287 | 315 | */ |