From 4ab7bd1e420f573b3cd1d5f7c799a6318852f13b Mon Sep 17 00:00:00 2001 From: Renato Alves <19148962+renatonascalves@users.noreply.github.com> Date: Sun, 21 Apr 2024 23:10:24 -0300 Subject: [PATCH] Messages: minor tweaks --- .../class-bp-rest-messages-endpoint.php | 18 ++---------------- tests/testcases/messages/test-controller.php | 11 ++++++++++- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/includes/bp-messages/classes/class-bp-rest-messages-endpoint.php b/includes/bp-messages/classes/class-bp-rest-messages-endpoint.php index 05f72bb6..93450e04 100644 --- a/includes/bp-messages/classes/class-bp-rest-messages-endpoint.php +++ b/includes/bp-messages/classes/class-bp-rest-messages-endpoint.php @@ -12,8 +12,8 @@ * Messages endpoints. * * /messages/ - * /messages/{id} * /messages/{thread_id} + * /messages//starred{message_id} * * @since 0.1.0 */ @@ -62,15 +62,6 @@ public function register_routes() { $this->namespace, $thread_endpoint, array( - 'args' => array( - 'id' => array( - 'description' => __( 'ID of the thread.', 'buddypress' ), - 'type' => 'integer', - 'required' => true, - 'sanitize_callback' => 'absint', - 'validate_callback' => 'rest_validate_request_arg', - ), - ), array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), @@ -102,12 +93,6 @@ public function register_routes() { $this->namespace, $starred_endpoint, array( - 'args' => array( - 'id' => array( - 'description' => __( 'ID of one of the message of the Thread.', 'buddypress' ), - 'type' => 'integer', - ), - ), array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => array( $this, 'update_starred' ), @@ -681,6 +666,7 @@ public function update_starred_permissions_check( $request ) { ); if ( is_user_logged_in() ) { + // The id here is for the message id. $thread_id = messages_get_message_thread_id( $request->get_param( 'id' ) ); if ( messages_check_thread_access( $thread_id ) ) { diff --git a/tests/testcases/messages/test-controller.php b/tests/testcases/messages/test-controller.php index 9f1bffbf..f16cadf2 100644 --- a/tests/testcases/messages/test-controller.php +++ b/tests/testcases/messages/test-controller.php @@ -185,7 +185,7 @@ public function test_get_item() { /** * @group get_item */ - public function test_get_item_messages() { + public function test_get_thread_messages_paginated() { $u1 = $this->factory->user->create(); $u2 = $this->factory->user->create(); $m = $this->bp_factory->message->create_and_get( array( @@ -195,6 +195,14 @@ public function test_get_item_messages() { 'content' => 'Content', ) ); + // create several messages. + $this->bp_factory->message->create_many( 10, array( + 'thread_id' => $m->thread_id, + 'sender_id' => $u2, + 'recipients' => array( $u1 ), + 'content' => 'Bar', + ) ); + // create a reply. $message_id = $this->bp_factory->message->create( array( 'sender_id' => $u2, @@ -215,6 +223,7 @@ public function test_get_item_messages() { $all_data = current( $response->get_data() ); $this->assertCount( 1, $all_data['messages'] ); + $this->assertSame( $m->thread_id, $all_data['messages'][0]['thread_id'] ); $this->assertSame( $message_id, $all_data['messages'][0]['id'] ); }