Changeset 12984
- Timestamp:
- 07/02/2021 01:10:12 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-messages/bp-messages-functions.php
r12592 r12984 325 325 * Wrapper for {@link BP_Messages_Thread::mark_as_read()}. 326 326 * 327 * @param int $thread_id ID of the thread. 327 * @since 9.0.0 Added the `user_id` parameter. 328 * 329 * @param int $thread_id The message thread ID. 330 * @param int $user_id Optional. The user the thread will be marked as read. 328 331 * 329 332 * @return false|int Number of threads marked as read or false on error. 330 333 */ 331 function messages_mark_thread_read( $thread_id ) {332 return BP_Messages_Thread::mark_as_read( $thread_id );334 function messages_mark_thread_read( $thread_id, $user_id = 0 ) { 335 return BP_Messages_Thread::mark_as_read( $thread_id, $user_id ); 333 336 } 334 337 … … 338 341 * Wrapper for {@link BP_Messages_Thread::mark_as_unread()}. 339 342 * 340 * @param int $thread_id ID of the thread. 343 * @since 9.0.0 Added the `user_id` parameter. 344 * 345 * @param int $thread_id The message thread ID. 346 * @param int $user_id Optional. The user the thread will be marked as unread. 341 347 * 342 348 * @return false|int Number of threads marked as unread or false on error. 343 349 */ 344 function messages_mark_thread_unread( $thread_id ) {345 return BP_Messages_Thread::mark_as_unread( $thread_id );350 function messages_mark_thread_unread( $thread_id, $user_id = 0 ) { 351 return BP_Messages_Thread::mark_as_unread( $thread_id, $user_id ); 346 352 } 347 353 -
trunk/src/bp-messages/classes/class-bp-messages-thread.php
r12592 r12984 613 613 * 614 614 * @since 1.0.0 615 * @since 9.0.0 Added the `user_id` parameter. 615 616 * 616 617 * @param int $thread_id The message thread ID. 618 * @param int $user_id The user the thread will be marked as read. 617 619 * 618 620 * @return false|int Number of threads marked as read or false on error. 619 621 */ 620 public static function mark_as_read( $thread_id = 0 ) { 621 global $wpdb; 622 623 $user_id = 624 bp_displayed_user_id() ? 625 bp_displayed_user_id() : 626 bp_loggedin_user_id(); 622 public static function mark_as_read( $thread_id = 0, $user_id = 0 ) { 623 global $wpdb; 624 625 if ( empty( $user_id ) ) { 626 $user_id = 627 bp_displayed_user_id() ? 628 bp_displayed_user_id() : 629 bp_loggedin_user_id(); 630 } 627 631 628 632 $bp = buddypress(); … … 636 640 * 637 641 * @since 2.8.0 642 * @since 9.0.0 Added the `user_id` parameter. 638 643 * 639 644 * @param int $thread_id The message thread ID. 645 * @param int $user_id The user the thread will be marked as read. 640 646 */ 641 do_action( 'messages_thread_mark_as_read', $thread_id );647 do_action( 'messages_thread_mark_as_read', $thread_id, $user_id ); 642 648 643 649 return $retval; … … 648 654 * 649 655 * @since 1.0.0 656 * @since 9.0.0 Added the `user_id` parameter. 650 657 * 651 658 * @param int $thread_id The message thread ID. 659 * @param int $user_id The user the thread will be marked as unread. 652 660 * 653 661 * @return false|int Number of threads marked as unread or false on error. 654 662 */ 655 public static function mark_as_unread( $thread_id = 0 ) { 656 global $wpdb; 657 658 $user_id = 659 bp_displayed_user_id() ? 660 bp_displayed_user_id() : 661 bp_loggedin_user_id(); 663 public static function mark_as_unread( $thread_id = 0, $user_id = 0 ) { 664 global $wpdb; 665 666 if ( empty( $user_id ) ) { 667 $user_id = 668 bp_displayed_user_id() ? 669 bp_displayed_user_id() : 670 bp_loggedin_user_id(); 671 } 662 672 663 673 $bp = buddypress(); … … 671 681 * 672 682 * @since 2.8.0 683 * @since 9.0.0 Added the `user_id` parameter. 673 684 * 674 685 * @param int $thread_id The message thread ID. 686 * @param int $user_id The user the thread will be marked as unread. 675 687 */ 676 do_action( 'messages_thread_mark_as_unread', $thread_id );688 do_action( 'messages_thread_mark_as_unread', $thread_id, $user_id ); 677 689 678 690 return $retval; -
trunk/tests/phpunit/testcases/messages/class.bp-messages-thread.php
r11737 r12984 320 320 321 321 /** 322 * @group cache 323 */ 324 public function test_marking_a_thread_as_read_with_specific_user_id() { 325 $u1 = self::factory()->user->create(); 326 $u2 = self::factory()->user->create(); 327 $message = self::factory()->message->create_and_get( array( 328 'sender_id' => $u1, 329 'recipients' => array( $u2 ), 330 'subject' => 'Foo', 331 ) ); 332 333 $thread_id = $message->thread_id; 334 335 // Cache should be populated. 336 $this->assertTrue( (bool) wp_cache_get( 'thread_recipients_' . $thread_id, 'bp_messages' ) ); 337 338 // Mark thread as read. 339 messages_mark_thread_read( $thread_id, $u2 ); 340 341 // Cache should be empty. 342 $this->assertFalse( wp_cache_get( 'thread_recipients_' . $thread_id, 'bp_messages' ) ); 343 344 $thread = new BP_Messages_Thread( $thread_id ); 345 346 $this->assertFalse( (bool) $thread->unread_count ); 347 $this->assertFalse( (bool) $thread->recipients[ $u1 ]->unread_count ); 348 $this->assertFalse( (bool) $thread->recipients[ $u2 ]->unread_count ); 349 } 350 351 /** 352 * @group cache 353 */ 354 public function test_marking_a_thread_as_unread_with_specific_user_id() { 355 $u1 = self::factory()->user->create(); 356 $u2 = self::factory()->user->create(); 357 $message = self::factory()->message->create_and_get( array( 358 'sender_id' => $u1, 359 'recipients' => array( $u2 ), 360 'subject' => 'Foo', 361 ) ); 362 363 $thread_id = $message->thread_id; 364 365 // Cache should be populated. 366 $this->assertTrue( (bool) wp_cache_get( 'thread_recipients_' . $thread_id, 'bp_messages' ) ); 367 368 // Mark thread as unread. 369 messages_mark_thread_unread( $thread_id, $u2 ); 370 371 // Cache should be empty. 372 $this->assertFalse( wp_cache_get( 'thread_recipients_' . $thread_id, 'bp_messages' ) ); 373 374 $thread = new BP_Messages_Thread( $thread_id ); 375 376 $this->assertFalse( (bool) $thread->recipients[ $u1 ]->unread_count ); 377 $this->assertTrue( (bool) $thread->recipients[ $u2 ]->unread_count ); 378 } 379 380 /** 322 381 * @group get_recipients 323 382 * @group cache
Note: See TracChangeset
for help on using the changeset viewer.