<!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->prepare( " AND r.unread_count = 0 " );
</span><span class="cx">
</span><del>-                $sql = $wpdb->prepare( "SELECT r.thread_id FROM {$bp->messages->table_name_recipients} r, {$bp->messages->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", $bp->loggedin_user->id );
</del><ins>+                $exclude_sender = false;
+                if ( 'inbox' == $box )
+                        $exclude_sender = $wpdb->prepare( " AND r.sender_only = 0" );
</ins><span class="cx">
</span><del>-                if ( !$thread_ids = $wpdb->get_results($sql) )
-                        return false;
</del><ins>+                $thread_ids = $wpdb->get_col( $wpdb->prepare( "SELECT r.thread_id FROM {$bp->messages->table_name_recipients} r, {$bp->messages->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", $bp->loggedin_user->id ) );
+                $total_threads = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(r.thread_id) FROM {$bp->messages->table_name_recipients} r, {$bp->messages->table_name_threads} t WHERE t.id = r.thread_id AND r.is_deleted = 0 AND r.user_id = %d$exclude_sender $type_sql", $bp->loggedin_user->id ) );
</ins><span class="cx">
</span><span class="cx">                 $threads = false;
</span><ins>+                foreach ( $thread_ids as $thread_id ) {
+                        if ( 'sentbox' == $box && !BP_Messages_Thread::user_is_sender( $thread_id ) ) {
+                                $total_threads--;
+                                continue;
+                        }
</ins><span class="cx">
</span><del>-                for ( $i = 0; $i < count($thread_ids); $i++ ) {
-                        $threads[$i] = new BP_Messages_Thread( $thread_ids[$i]->thread_id, false, $box );
-
-                        if ( !$threads[$i]->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' => &$threads, 'total' => (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->query($sql) )
</span><span class="cx">                                 return false;
</span><span class="cx">
</span><del>-
</del><span class="cx">                         $this->thread_id = $wpdb->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->sender_id, (array)$this->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->query( $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_recipients} ( user_id, thread_id, unread_count, sender_only ) VALUES ( %d, %d, 0, 0 )", $this->sender_id, $this->thread_id ) );
</del><ins>+                                $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->messages->table_name_recipients} ( user_id, thread_id, unread_count, sender_only ) VALUES ( %d, %d, 0, 1 )", $this->sender_id, $this->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->box )
</span><span class="cx">                         $this->threads = BP_Messages_Notice::get_notices();
</span><del>-                else
-                        $this->threads = BP_Messages_Thread::get_current_threads_for_user( $this->user_id, $this->box, $this->pag_num, $this->pag_page, $type );
</del><ins>+                else {
+                        $threads = BP_Messages_Thread::get_current_threads_for_user( $this->user_id, $this->box, $this->pag_num, $this->pag_page, $type );
</ins><span class="cx">
</span><ins>+                        $this->threads = $threads['threads'];
+                        $this->total_thread_count = $threads['total'];
+                }
+
</ins><span class="cx">                 if ( !$this->threads ) {
</span><span class="cx">                         $this->thread_count = 0;
</span><span class="cx">                         $this->total_thread_count = 0;
</span><span class="lines">@@ -39,8 +43,6 @@
</span><span class="cx">                         if ( !$max || $max >= (int)$total_notice_count ) {
</span><span class="cx">                                 if ( 'notices' == $this->box )
</span><span class="cx">                                         $this->total_thread_count = (int)$total_notice_count;
</span><del>-                                else
-                                        $this->total_thread_count = (int)BP_Messages_Thread::get_total_threads_for_user( $this->user_id, $this->box, $type );
</del><span class="cx">                         } else {
</span><span class="cx">                                 $this->total_thread_count = (int)$max;
</span><span class="cx">                         }
</span><span class="lines">@@ -60,8 +62,8 @@
</span><span class="cx">                         'format' => '',
</span><span class="cx">                         'total' => ceil($this->total_thread_count / $this->pag_num),
</span><span class="cx">                         'current' => $this->pag_page,
</span><del>-                        'prev_text' => '&laquo;',
-                        'next_text' => '&raquo;',
</del><ins>+                        'prev_text' => '&larr;',
+                        'next_text' => '&rarr;',
</ins><span class="cx">                         'mid_size' => 1
</span><span class="cx">                 ));
</span><span class="cx">         }
</span></span></pre>
</div>
</div>
</body>
</html>