<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[BuddyPress] [3384] trunk: Allows private message thread ordering.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>3384</dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2010-11-09 23:50:47 +0000 (Tue, 09 Nov 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Allows private message thread ordering. Fixes #2724. Props aesqe</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpmessagesbpmessagesclassesphp">trunk/bp-messages/bp-messages-classes.php</a></li>
<li><a href="#trunkbpmessagesbpmessagestemplatetagsphp">trunk/bp-messages/bp-messages-templatetags.php</a></li>
<li><a href="#trunkbpthemesbpdefault_incglobaljs">trunk/bp-themes/bp-default/_inc/global.js</a></li>
<li><a href="#trunkbpthemesbpdefaultmemberssinglemessagessinglephp">trunk/bp-themes/bp-default/members/single/messages/single.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpmessagesbpmessagesclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-messages/bp-messages-classes.php (3383 => 3384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-messages/bp-messages-classes.php        2010-11-09 17:01:26 UTC (rev 3383)
+++ trunk/bp-messages/bp-messages-classes.php        2010-11-09 23:50:47 UTC (rev 3384)
</span><span class="lines">@@ -8,17 +8,21 @@
</span><span class="cx"> 
</span><span class="cx">         var $unread_count;
</span><span class="cx"> 
</span><del>-        function bp_messages_thread ( $thread_id = false ) {
</del><ins>+        function bp_messages_thread ( $thread_id = false, $order = 'ASC' ) {
</ins><span class="cx">                 if ( $thread_id )
</span><del>-                        $this-&gt;populate( $thread_id );
</del><ins>+                        $this-&gt;populate( $thread_id, $order );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function populate( $thread_id ) {
</del><ins>+        function populate( $thread_id, $order ) {
</ins><span class="cx">                 global $wpdb, $bp;
</span><span class="cx"> 
</span><ins>+                if( 'ASC' != $order &amp;&amp; 'DESC' != $order )
+                        $order= 'ASC';
+
+                $this-&gt;messages_order = $order;
</ins><span class="cx">                 $this-&gt;thread_id = $thread_id;
</span><span class="cx"> 
</span><del>-                if ( !$this-&gt;messages = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT * FROM {$bp-&gt;messages-&gt;table_name_messages} WHERE thread_id = %d ORDER BY date_sent ASC&quot;, $this-&gt;thread_id ) ) )
</del><ins>+                if ( !$this-&gt;messages = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT * FROM {$bp-&gt;messages-&gt;table_name_messages} WHERE thread_id = %d ORDER BY date_sent &quot; . $order, $this-&gt;thread_id ) ) )
</ins><span class="cx">                         return false;
</span><span class="cx"> 
</span><span class="cx">                 foreach ( (array)$this-&gt;messages as $key =&gt; $message )
</span></span></pre></div>
<a id="trunkbpmessagesbpmessagestemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-messages/bp-messages-templatetags.php (3383 => 3384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-messages/bp-messages-templatetags.php        2010-11-09 17:01:26 UTC (rev 3383)
+++ trunk/bp-messages/bp-messages-templatetags.php        2010-11-09 23:50:47 UTC (rev 3384)
</span><span class="lines">@@ -594,7 +594,7 @@
</span><span class="cx">         function bp_messages_thread_template( $thread_id, $order ) {
</span><span class="cx">                 global $bp;
</span><span class="cx"> 
</span><del>-                $this-&gt;thread = new BP_Messages_Thread( $thread_id, true );
</del><ins>+                $this-&gt;thread = new BP_Messages_Thread( $thread_id, $order );
</ins><span class="cx">                 $this-&gt;message_count = count( $this-&gt;thread-&gt;messages );
</span><span class="cx"> 
</span><span class="cx">                 $last_message_index = $this-&gt;message_count - 1;
</span><span class="lines">@@ -652,7 +652,7 @@
</span><span class="cx"> 
</span><span class="cx"> function bp_thread_has_messages( $args = '' ) {
</span><span class="cx">         global $bp, $thread_template, $group_id;
</span><del>-
</del><ins>+        
</ins><span class="cx">         $defaults = array(
</span><span class="cx">                 'thread_id' =&gt; false,
</span><span class="cx">                 'order' =&gt; 'ASC'
</span><span class="lines">@@ -668,6 +668,15 @@
</span><span class="cx">         return $thread_template-&gt;has_messages();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+function bp_thread_messages_order() {
+        echo bp_get_thread_messages_order();
+}
+
+        function bp_get_thread_messages_order() {
+                global $thread_template;
+                return $thread_template-&gt;thread-&gt;messages_order;
+        }
+
</ins><span class="cx"> function bp_thread_messages() {
</span><span class="cx">         global $thread_template;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkbpthemesbpdefault_incglobaljs"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/_inc/global.js (3383 => 3384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/_inc/global.js        2010-11-09 17:01:26 UTC (rev 3383)
+++ trunk/bp-themes/bp-default/_inc/global.js        2010-11-09 23:50:47 UTC (rev 3384)
</span><span class="lines">@@ -837,6 +837,9 @@
</span><span class="cx">         /* AJAX send reply functionality */
</span><span class="cx">         jq(&quot;input#send_reply_button&quot;).click(
</span><span class="cx">                 function() {
</span><ins>+                        var order = jq('#messages_order').val() || 'ASC',
+                                offset = jq('#message-recipients').offset();
+
</ins><span class="cx">                         jq('form#send-reply span.ajax-loader').toggle();
</span><span class="cx"> 
</span><span class="cx">                         jq.post( ajaxurl, {
</span><span class="lines">@@ -856,8 +859,14 @@
</span><span class="cx">                                 } else {
</span><span class="cx">                                         jq('form#send-reply div#message').remove();
</span><span class="cx">                                         jq(&quot;#message_content&quot;).val('');
</span><del>-                                        jq('form#send-reply').before( response );
</del><span class="cx"> 
</span><ins>+                                        if ( 'ASC' == order ) {
+                                                jq('form#send-reply').before( response );
+                                        } else {
+                                                jq('#message-recipients').after( response );
+                                                jq(window).scrollTop(offset.top);
+                                        }
+
</ins><span class="cx">                                         jq(&quot;div.new-message&quot;).hide().slideDown( 200, function() {
</span><span class="cx">                                                 jq('div.new-message').removeClass('new-message');
</span><span class="cx">                                         });
</span></span></pre></div>
<a id="trunkbpthemesbpdefaultmemberssinglemessagessinglephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/members/single/messages/single.php (3383 => 3384)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/members/single/messages/single.php        2010-11-09 17:01:26 UTC (rev 3383)
+++ trunk/bp-themes/bp-default/members/single/messages/single.php        2010-11-09 23:50:47 UTC (rev 3384)
</span><span class="lines">@@ -81,6 +81,7 @@
</span><span class="cx">                                         &lt;/div&gt;
</span><span class="cx"> 
</span><span class="cx">                                         &lt;input type=&quot;hidden&quot; id=&quot;thread_id&quot; name=&quot;thread_id&quot; value=&quot;&lt;?php bp_the_thread_id(); ?&gt;&quot; /&gt;
</span><ins>+                                        &lt;input type=&quot;hidden&quot; id=&quot;messages_order&quot; name=&quot;messages_order&quot; value=&quot;&lt;?php bp_thread_messages_order(); ?&gt;&quot; /&gt;
</ins><span class="cx">                                         &lt;?php wp_nonce_field( 'messages_send_message', 'send_message_nonce' ) ?&gt;
</span><span class="cx"> 
</span><span class="cx">                                 &lt;/div&gt;&lt;!-- .message-content --&gt;
</span></span></pre>
</div>
</div>

</body>
</html>