Skip to content

Commit

Permalink
Messages: minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
renatonascalves committed Apr 22, 2024
1 parent 1e37ca3 commit 4ab7bd1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
18 changes: 2 additions & 16 deletions includes/bp-messages/classes/class-bp-rest-messages-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* Messages endpoints.
*
* /messages/
* /messages/{id}
* /messages/{thread_id}
* /messages//starred{message_id}
*
* @since 0.1.0
*/
Expand Down Expand Up @@ -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' ),
Expand Down Expand Up @@ -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' ),
Expand Down Expand Up @@ -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 ) ) {
Expand Down
11 changes: 10 additions & 1 deletion tests/testcases/messages/test-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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'] );
}

Expand Down

0 comments on commit 4ab7bd1

Please sign in to comment.