Ticket #8750: 8750.patch
File 8750.patch, 3.3 KB (added by , 2 years ago) |
---|
-
src/bp-messages/classes/class-bp-messages-thread.php
diff --git src/bp-messages/classes/class-bp-messages-thread.php src/bp-messages/classes/class-bp-messages-thread.php index 4032bd6bd..0376074c5 100644
class BP_Messages_Thread { 200 200 $this->sender_ids[ $message->sender_id ] = $message->sender_id; 201 201 } 202 202 203 // Fetch the recipients .203 // Fetch the recipients and set the displayed/logged in user's unread count. 204 204 $this->recipients = $this->get_recipients( $thread_id, $r ); 205 205 206 // Get the unread count for the user.207 if ( isset( $this->recipients[ $r['user_id'] ] ) ) {208 $this->unread_count = $this->recipients[ $r['user_id'] ]->unread_count;209 }210 211 206 // Grab all message meta. 212 207 if ( true === (bool) $r['update_meta_cache'] ) { 213 208 bp_messages_update_meta_cache( wp_list_pluck( $this->messages, 'id' ) ); … … class BP_Messages_Thread { 311 306 wp_cache_set( 'thread_recipients_' . $thread_id, (array) $recipients, 'bp_messages' ); 312 307 } 313 308 309 // Set the unread count for the user. 310 if ( isset( $r['user_id'] ) && $r['user_id'] && isset( $recipients[ $r['user_id'] ]->unread_count ) ) { 311 $this->unread_count = (int) $recipients[ $r['user_id'] ]->unread_count; 312 } 313 314 314 // Paginate the results. 315 315 if ( ! empty( $recipients ) && $r['recipients_per_page'] && $r['recipients_page'] ) { 316 316 $start = ( $r['recipients_page'] - 1 ) * ( $r['recipients_per_page'] ); 317 $recipients = array_slice( $recipients, $start, $r['recipients_per_page'] );317 $recipients = array_slice( $recipients, $start, $r['recipients_per_page'], true ); 318 318 } 319 319 320 320 /** -
tests/phpunit/testcases/messages/template.php
diff --git tests/phpunit/testcases/messages/template.php tests/phpunit/testcases/messages/template.php index cd405ffb3..a2640848b 100644
class BP_Tests_Messages_Template extends BP_UnitTestCase { 424 424 $this->assertNotCount( 2, $messages_template->threads[0]->recipients ); 425 425 $this->assertCount( 1, $messages_template->threads[0]->recipients ); 426 426 } 427 428 /** 429 * @group pagination 430 * @group BP_Messages_Box_Template 431 * @group BP8750 432 */ 433 public function test_thread_unread_count_setting_per_page_recipients() { 434 $u1 = self::factory()->user->create(); 435 $u2 = self::factory()->user->create(); 436 437 // create initial thread 438 $message_1 = self::factory()->message->create_and_get( 439 array( 440 'sender_id' => $u1, 441 'recipients' => array( $u2 ), 442 ) 443 ); 444 445 // create some replies to thread 446 self::factory()->message->create_and_get( 447 array( 448 'thread_id' => $message_1->thread_id, 449 'sender_id' => $u2, 450 'recipients' => array( $u1 ), 451 ) 452 ); 453 454 self::factory()->message->create_and_get( 455 array( 456 'thread_id' => $message_1->thread_id, 457 'sender_id' => $u2, 458 'recipients' => array( $u1 ), 459 ) 460 ); 461 462 // set user to anonymous 463 $old_current_user = get_current_user_id(); 464 $this->set_current_user( $u1 ); 465 466 $messages_template = new BP_Messages_Box_Template( 467 array( 468 'recipients_page' => 1, 469 'recipients_per_page' => 1, 470 ) 471 ); 472 473 $this->set_current_user( $old_current_user ); 474 475 $thread = reset( $messages_template->threads ); 476 477 $this->assertEquals( 2, $thread->unread_count ); 478 } 427 479 }