<!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] [2182] trunk/bp-messages: Fixing messaging pagination counts.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>2182</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2009-12-15 14:37:11 +0000 (Tue, 15 Dec 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fixing messaging pagination counts.</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>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpmessagesbpmessagesclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-messages/bp-messages-classes.php (2181 => 2182)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-messages/bp-messages-classes.php        2009-12-15 14:11:12 UTC (rev 2181)
+++ trunk/bp-messages/bp-messages-classes.php        2009-12-15 14:37:11 UTC (rev 2182)
</span><span class="lines">@@ -190,22 +190,24 @@
</span><span class="cx">                 else if ( $type == 'read' )
</span><span class="cx">                         $type_sql = $wpdb-&gt;prepare( &quot; AND r.unread_count = 0 &quot; );
</span><span class="cx"> 
</span><del>-                $sql = $wpdb-&gt;prepare( &quot;SELECT r.thread_id FROM {$bp-&gt;messages-&gt;table_name_recipients} r, {$bp-&gt;messages-&gt;table_name_threads} t WHERE t.id = r.thread_id AND r.is_deleted = 0 AND r.user_id = %d$exclude_sender $type_sql ORDER BY t.last_post_date DESC$pag_sql&quot;, $bp-&gt;loggedin_user-&gt;id );
</del><ins>+                $exclude_sender = false;
+                if ( 'inbox' == $box )
+                        $exclude_sender = $wpdb-&gt;prepare( &quot; AND r.sender_only = 0&quot; );
</ins><span class="cx"> 
</span><del>-                if ( !$thread_ids = $wpdb-&gt;get_results($sql) )
-                        return false;
</del><ins>+                $thread_ids = $wpdb-&gt;get_col( $wpdb-&gt;prepare( &quot;SELECT r.thread_id FROM {$bp-&gt;messages-&gt;table_name_recipients} r, {$bp-&gt;messages-&gt;table_name_threads} t WHERE t.id = r.thread_id AND r.is_deleted = 0 AND r.user_id = %d$exclude_sender $type_sql ORDER BY t.last_post_date DESC$pag_sql&quot;, $bp-&gt;loggedin_user-&gt;id ) );
+                $total_threads = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT COUNT(r.thread_id) FROM {$bp-&gt;messages-&gt;table_name_recipients} r, {$bp-&gt;messages-&gt;table_name_threads} t WHERE t.id = r.thread_id AND r.is_deleted = 0 AND r.user_id = %d$exclude_sender $type_sql&quot;, $bp-&gt;loggedin_user-&gt;id ) );
</ins><span class="cx"> 
</span><span class="cx">                 $threads = false;
</span><ins>+                foreach ( $thread_ids as $thread_id ) {
+                        if ( 'sentbox' == $box &amp;&amp; !BP_Messages_Thread::user_is_sender( $thread_id ) ) {
+                                $total_threads--;
+                                continue;
+                        }
</ins><span class="cx"> 
</span><del>-                for ( $i = 0; $i &lt; count($thread_ids); $i++ ) {
-                        $threads[$i] = new BP_Messages_Thread( $thread_ids[$i]-&gt;thread_id, false, $box );
-
-                        if ( !$threads[$i]-&gt;message_ids )
-                                unset($threads[$i]);
</del><ins>+                        $threads[] = new BP_Messages_Thread( $thread_id, false, $box );
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                // reset keys
-                return array_reverse( array_reverse( $threads ) );
</del><ins>+                return array( 'threads' =&gt; &amp;$threads, 'total' =&gt; (int)$total_threads );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function mark_as_read( $thread_id ) {
</span><span class="lines">@@ -395,7 +397,6 @@
</span><span class="cx">                         if ( false === $wpdb-&gt;query($sql) )
</span><span class="cx">                                 return false;
</span><span class="cx"> 
</span><del>-
</del><span class="cx">                         $this-&gt;thread_id = $wpdb-&gt;insert_id;
</span><span class="cx"> 
</span><span class="cx">                         // Add a new entry for each recipient;
</span><span class="lines">@@ -405,7 +406,7 @@
</span><span class="cx"> 
</span><span class="cx">                         if ( !in_array( $this-&gt;sender_id, (array)$this-&gt;recipients ) ) {
</span><span class="cx">                                 // Finally, add a recipient entry for the sender, as replies need to go to this person too.
</span><del>-                                $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;INSERT INTO {$bp-&gt;messages-&gt;table_name_recipients} ( user_id, thread_id, unread_count, sender_only ) VALUES ( %d, %d, 0, 0 )&quot;, $this-&gt;sender_id, $this-&gt;thread_id ) );
</del><ins>+                                $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;INSERT INTO {$bp-&gt;messages-&gt;table_name_recipients} ( user_id, thread_id, unread_count, sender_only ) VALUES ( %d, %d, 0, 1 )&quot;, $this-&gt;sender_id, $this-&gt;thread_id ) );
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkbpmessagesbpmessagestemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-messages/bp-messages-templatetags.php (2181 => 2182)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-messages/bp-messages-templatetags.php        2009-12-15 14:11:12 UTC (rev 2181)
+++ trunk/bp-messages/bp-messages-templatetags.php        2009-12-15 14:37:11 UTC (rev 2182)
</span><span class="lines">@@ -27,9 +27,13 @@
</span><span class="cx"> 
</span><span class="cx">                 if ( 'notices' == $this-&gt;box )
</span><span class="cx">                         $this-&gt;threads = BP_Messages_Notice::get_notices();
</span><del>-                else
-                        $this-&gt;threads = BP_Messages_Thread::get_current_threads_for_user( $this-&gt;user_id, $this-&gt;box, $this-&gt;pag_num, $this-&gt;pag_page, $type );
</del><ins>+                else {
+                        $threads = BP_Messages_Thread::get_current_threads_for_user( $this-&gt;user_id, $this-&gt;box, $this-&gt;pag_num, $this-&gt;pag_page, $type );
</ins><span class="cx"> 
</span><ins>+                        $this-&gt;threads = $threads['threads'];
+                        $this-&gt;total_thread_count = $threads['total'];
+                }
+
</ins><span class="cx">                 if ( !$this-&gt;threads ) {
</span><span class="cx">                         $this-&gt;thread_count = 0;
</span><span class="cx">                         $this-&gt;total_thread_count = 0;
</span><span class="lines">@@ -39,8 +43,6 @@
</span><span class="cx">                         if ( !$max || $max &gt;= (int)$total_notice_count ) {
</span><span class="cx">                                 if ( 'notices' == $this-&gt;box )
</span><span class="cx">                                         $this-&gt;total_thread_count = (int)$total_notice_count;
</span><del>-                                else
-                                        $this-&gt;total_thread_count = (int)BP_Messages_Thread::get_total_threads_for_user( $this-&gt;user_id, $this-&gt;box, $type );
</del><span class="cx">                         } else {
</span><span class="cx">                                 $this-&gt;total_thread_count = (int)$max;
</span><span class="cx">                         }
</span><span class="lines">@@ -60,8 +62,8 @@
</span><span class="cx">                         'format' =&gt; '',
</span><span class="cx">                         'total' =&gt; ceil($this-&gt;total_thread_count / $this-&gt;pag_num),
</span><span class="cx">                         'current' =&gt; $this-&gt;pag_page,
</span><del>-                        'prev_text' =&gt; '&amp;laquo;',
-                        'next_text' =&gt; '&amp;raquo;',
</del><ins>+                        'prev_text' =&gt; '&amp;larr;',
+                        'next_text' =&gt; '&amp;rarr;',
</ins><span class="cx">                         'mid_size' =&gt; 1
</span><span class="cx">                 ));
</span><span class="cx">         }
</span></span></pre>
</div>
</div>

</body>
</html>