<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][14069] trunk: Messages: filter threads by recipient IDs.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://buddypress.trac.wordpress.org/changeset/14069">14069</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://buddypress.trac.wordpress.org/changeset/14069","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>espellcaste</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-11-03 17:55:47 +0000 (Sun, 03 Nov 2024)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Messages: filter threads by recipient IDs.
`bp_has_message_threads` (and the BP REST API) can filter thread(s) messages by recipient IDs. Very useful when trying to identify if a member already messaged another.
Props imath and slaFFik.
See https://github.com/buddypress/BP-REST/issues/455
Closes https://github.com/buddypress/buddypress/pull/394
See <a href="http://buddypress.trac.wordpress.org/ticket/9229">#9229</a> and <a href="http://buddypress.trac.wordpress.org/ticket/9145">#9145</a>
Fixes <a href="http://buddypress.trac.wordpress.org/ticket/9157">#9157</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcbpmessagesbpmessagestemplatephp">trunk/src/bp-messages/bp-messages-template.php</a></li>
<li><a href="#trunksrcbpmessagesclassesclassbpmessagesboxtemplatephp">trunk/src/bp-messages/classes/class-bp-messages-box-template.php</a></li>
<li><a href="#trunksrcbpmessagesclassesclassbpmessagesrestcontrollerphp">trunk/src/bp-messages/classes/class-bp-messages-rest-controller.php</a></li>
<li><a href="#trunksrcbpmessagesclassesclassbpmessagesthreadphp">trunk/src/bp-messages/classes/class-bp-messages-thread.php</a></li>
<li><a href="#trunktestsphpunittestcasesmessagestestcontrollerphp">trunk/tests/phpunit/testcases/messages/test-controller.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcbpmessagesbpmessagestemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-messages/bp-messages-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-messages/bp-messages-template.php 2024-11-01 06:07:04 UTC (rev 14068)
+++ trunk/src/bp-messages/bp-messages-template.php 2024-11-03 17:55:47 UTC (rev 14069)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -18,6 +18,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * the theme via individual template parts for a member's inbox/sentbox/notices.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.0.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 15.0.0 Added the `$includes` parameter.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @global BP_Messages_Box_Template $messages_template The message box template loop class.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -31,6 +32,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @type int $max Max results to return. Default: false.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $type Type of messages to return. Values: 'all', 'read', 'unread'
</span><span class="cx" style="display: block; padding: 0 10px"> * Default: 'all'
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type array $includes Filter threads by recipient IDs.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @type string $search_terms Terms to which to limit results. Default:
</span><span class="cx" style="display: block; padding: 0 10px"> * the value of $_REQUEST['s'].
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $page_arg URL argument used for the pagination param.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -79,6 +81,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'search_terms' => $search_terms,
</span><span class="cx" style="display: block; padding: 0 10px"> 'page_arg' => 'mpage', // See https://buddypress.trac.wordpress.org/ticket/3679.
</span><span class="cx" style="display: block; padding: 0 10px"> 'meta_query' => array(),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'includes' => array(),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'recipients_page' => null,
</span><span class="cx" style="display: block; padding: 0 10px"> 'recipients_per_page' => null,
</span><span class="cx" style="display: block; padding: 0 10px"> 'messages_page' => null,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -95,7 +98,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.1.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool $value Whether or not the message has threads.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param bool $has_threads Whether or not the message has threads.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param BP_Messages_Box_Template $messages_template Current message box template object.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $r Array of parsed arguments passed into function.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span></span></pre></div>
<a id="trunksrcbpmessagesclassesclassbpmessagesboxtemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-messages/classes/class-bp-messages-box-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-messages/classes/class-bp-messages-box-template.php 2024-11-01 06:07:04 UTC (rev 14068)
+++ trunk/src/bp-messages/classes/class-bp-messages-box-template.php 2024-11-03 17:55:47 UTC (rev 14069)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -168,6 +168,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'user_id' => bp_loggedin_user_id(),
</span><span class="cx" style="display: block; padding: 0 10px"> 'max' => false,
</span><span class="cx" style="display: block; padding: 0 10px"> 'search_terms' => '',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'includes' => array(),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'meta_query' => array(),
</span><span class="cx" style="display: block; padding: 0 10px"> 'recipients_page' => null,
</span><span class="cx" style="display: block; padding: 0 10px"> 'recipients_per_page' => null,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -200,6 +201,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'limit' => $this->pag_num,
</span><span class="cx" style="display: block; padding: 0 10px"> 'page' => $this->pag_page,
</span><span class="cx" style="display: block; padding: 0 10px"> 'search_terms' => $this->search_terms,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'includes' => $r['includes'],
</ins><span class="cx" style="display: block; padding: 0 10px"> 'meta_query' => $r['meta_query'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'recipients_page' => $r['recipients_page'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'recipients_per_page' => $r['recipients_per_page'],
</span></span></pre></div>
<a id="trunksrcbpmessagesclassesclassbpmessagesrestcontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-messages/classes/class-bp-messages-rest-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-messages/classes/class-bp-messages-rest-controller.php 2024-11-01 06:07:04 UTC (rev 14068)
+++ trunk/src/bp-messages/classes/class-bp-messages-rest-controller.php 2024-11-03 17:55:47 UTC (rev 14069)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -124,6 +124,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'box' => $request->get_param( 'box' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => $request->get_param( 'type' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'page' => $request->get_param( 'page' ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'includes' => $request->get_param( 'includes' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'per_page' => $request->get_param( 'per_page' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'search_terms' => $request->get_param( 'search' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'recipients_page' => $request->get_param( 'recipients_page' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1539,7 +1540,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $params['box'] = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'description' => __( 'Filter the result by box.', 'buddypress' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'description' => __( 'Filter threads by the mailbox type.', 'buddypress' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'default' => 'inbox',
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'string',
</span><span class="cx" style="display: block; padding: 0 10px"> 'enum' => $boxes,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1548,7 +1549,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $params['type'] = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'description' => __( 'Filter the result by thread status.', 'buddypress' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'description' => __( 'Filter threads by the status.', 'buddypress' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'default' => 'all',
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'string',
</span><span class="cx" style="display: block; padding: 0 10px"> 'enum' => array( 'all', 'read', 'unread' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1565,6 +1566,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'validate_callback' => 'rest_validate_request_arg',
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $params['includes'] = array(
+ 'description' => __( 'Filter threads by recipient IDs.', 'buddypress' ),
+ 'default' => array(),
+ 'type' => 'array',
+ 'sanitize_callback' => 'wp_parse_id_list',
+ 'validate_callback' => 'rest_validate_request_arg',
+ );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $params['recipients_page'] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'Current page of the recipients collection.', 'buddypress' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'integer',
</span></span></pre></div>
<a id="trunksrcbpmessagesclassesclassbpmessagesthreadphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/bp-messages/classes/class-bp-messages-thread.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/bp-messages/classes/class-bp-messages-thread.php 2024-11-01 06:07:04 UTC (rev 14068)
+++ trunk/src/bp-messages/classes/class-bp-messages-thread.php 2024-11-03 17:55:47 UTC (rev 14069)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -672,6 +672,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Get current message threads for a user.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.0.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 15.0.0 Added the `$includes` parameter.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @global wpdb $wpdb WordPress database object.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -684,6 +685,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * or 'read'. Defaults to 'all'.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type int $limit The number of messages to get. Defaults to null.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type int $page The page number to get. Defaults to null.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type array $includes Filter threads by recipient IDs.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @type string $search_terms The search term to use. Defaults to ''.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type array $meta_query Meta query arguments. See WP_Meta_Query for more details.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type int|null $recipients_page Page of recipients being requested. Default to null, meaning all.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -730,6 +732,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'box' => 'inbox',
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'all',
</span><span class="cx" style="display: block; padding: 0 10px"> 'limit' => null,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'includes' => array(),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'page' => null,
</span><span class="cx" style="display: block; padding: 0 10px"> 'recipients_page' => null,
</span><span class="cx" style="display: block; padding: 0 10px"> 'recipients_per_page' => null,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -740,7 +743,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> )
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $pag_sql = $type_sql = $search_sql = $user_id_sql = $sender_sql = '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $pag_sql = $type_sql = $search_sql = $user_id_sql = $includes_sql = $sender_sql = '';
</ins><span class="cx" style="display: block; padding: 0 10px"> $meta_query_sql = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'join' => '',
</span><span class="cx" style="display: block; padding: 0 10px"> 'where' => '',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -794,11 +797,26 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $bp = buddypress();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $r['includes'] ) && is_array( $r['includes'] ) ) {
+ $includes_ids = array_filter(
+ wp_parse_id_list( $r['includes'] ),
+ function ( $recipient_id ) use ( $r ) {
+ // Filter out the current user ID, if available.
+ return $recipient_id !== $r['user_id'];
+ }
+ );
+
+ if ( ! empty( $includes_ids ) ) {
+ $includes_ids = implode( ',', $includes_ids );
+ $includes_sql = "AND r.thread_id IN (SELECT thread_id FROM {$bp->messages->table_name_recipients} WHERE user_id in ({$includes_ids}))";
+ }
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Set up SQL array.
</span><span class="cx" style="display: block; padding: 0 10px"> $sql = array();
</span><span class="cx" style="display: block; padding: 0 10px"> $sql['select'] = 'SELECT m.thread_id, MAX(m.date_sent) AS date_sent';
</span><span class="cx" style="display: block; padding: 0 10px"> $sql['from'] = "FROM {$bp->messages->table_name_recipients} r INNER JOIN {$bp->messages->table_name_messages} m ON m.thread_id = r.thread_id {$meta_query_sql['join']}";
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $sql['where'] = "WHERE {$deleted_sql} {$user_id_sql} {$sender_sql} {$type_sql} {$search_sql} {$meta_query_sql['where']}";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $sql['where'] = "WHERE {$deleted_sql} {$user_id_sql} {$sender_sql} {$includes_sql} {$type_sql} {$search_sql} {$meta_query_sql['where']}";
</ins><span class="cx" style="display: block; padding: 0 10px"> $sql['misc'] = "GROUP BY m.thread_id ORDER BY date_sent DESC {$pag_sql}";
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Get thread IDs.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -810,6 +828,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Adjust $sql to work for thread total.
</span><span class="cx" style="display: block; padding: 0 10px"> $sql['select'] = 'SELECT COUNT( DISTINCT m.thread_id )';
</span><span class="cx" style="display: block; padding: 0 10px"> unset( $sql['misc'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $total_threads = $wpdb->get_var( implode( ' ', $sql ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Sort threads by date_sent.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -840,11 +859,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.2.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $value {
- * @type array $threads Array of threads. Passed by reference.
- * @type int $total_threads Number of threads found by the query.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $results {
+ * @type BP_Messages_Thread[] $threads Array of threads. Passed by reference.
+ * @type int $total_threads Number of threads found by the query.
</ins><span class="cx" style="display: block; padding: 0 10px"> * }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $r Array of parameters.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $r Array of parameters.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> return apply_filters(
</span><span class="cx" style="display: block; padding: 0 10px"> 'bp_messages_thread_current_threads',
</span></span></pre></div>
<a id="trunktestsphpunittestcasesmessagestestcontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/testcases/messages/test-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/testcases/messages/test-controller.php 2024-11-01 06:07:04 UTC (rev 14068)
+++ trunk/tests/phpunit/testcases/messages/test-controller.php 2024-11-03 17:55:47 UTC (rev 14069)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -71,7 +71,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertCount( 1, $a_ids );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertCount( 1, $data[0]['messages'] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Check the thread data for the requested user id => `$u1`.
</del><span class="cx" style="display: block; padding: 0 10px"> $this->check_thread_data( $this->endpoint->get_thread_object( $data[0]['id'], $u1 ), $data[0] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -145,6 +144,67 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @BP9157
+ * @group get_items
+ */
+ public function test_filter_threads_by_recipients() {
+ $u1 = static::factory()->user->create();
+ $u2 = static::factory()->user->create();
+ $u3 = static::factory()->user->create();
+
+ $thread = $this->bp::factory()->message->create_and_get(
+ array(
+ 'sender_id' => $u1,
+ 'recipients' => array( $u2 ),
+ 'subject' => 'First Thread',
+ )
+ );
+
+ $this->bp::factory()->message->create(
+ array(
+ 'thread_id' => $thread->thread_id,
+ 'sender_id' => $u2,
+ 'recipients' => array( $u1 ),
+ )
+ );
+
+ $thread2 = $this->bp::factory()->message->create_and_get(
+ array(
+ 'sender_id' => $u1,
+ 'recipients' => array( $u3 ),
+ 'subject' => 'Second Thread',
+ )
+ );
+
+ $this->bp::factory()->message->create(
+ array(
+ 'thread_id' => $thread2->thread_id,
+ 'sender_id' => $u3,
+ 'recipients' => array( $u1 ),
+ )
+ );
+
+ $this->bp::set_current_user( $this->user );
+
+ $request = new WP_REST_Request( 'GET', $this->endpoint_url );
+ $request->set_param( 'context', 'view' );
+ $request->set_param( 'user_id', $u1 );
+ $request->set_param( 'includes', array( $u3 ) );
+ $response = $this->server->dispatch( $request );
+
+ $this->assertEquals( 200, $response->get_status() );
+
+ $data = $response->get_data();
+
+ $this->assertNotEmpty( $data );
+
+ $a_ids = wp_list_pluck( $data, 'id' );
+
+ $this->assertCount( 1, $a_ids );
+ $this->assertSame( $thread2->thread_id, $a_ids[0] );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * @group get_item
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_get_item() {
</span></span></pre>
</div>
</div>
</body>
</html>