Index: privatemsg.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/privatemsg.module,v
retrieving revision 1.70.2.30.2.91.2.54
diff -u -r1.70.2.30.2.91.2.54 privatemsg.module
--- privatemsg.module	22 Jun 2009 18:32:43 -0000	1.70.2.30.2.91.2.54
+++ privatemsg.module	22 Jun 2009 19:11:24 -0000
@@ -848,7 +848,7 @@
   $fragments['select'][]      = 'MAX(pmi.is_new) as is_new';
 
   if (in_array('count', $fields)) {
-    $fragments['select'][]      = 'COUNT(pmi.thread_id) as count';
+    $fragments['select'][]      = 'COUNT(DISTINCT pmi.mid) as count';
   }
   if (in_array('participants', $fields)) {
     // Query for a string with uid's, for example "1,6,7". This needs a subquery on PostgreSQL.
@@ -888,7 +888,6 @@
  * Query function for load.
  */
 function privatemsg_sql_load(&$fragments, $pmid, $account) {
-//  drupal_set_message('<pre>'. print_r(func_get_args(), 1) . '</pre>');
   $fragments['primary_table'] = '{pm_message} pm'; // Our primary table
 
   $fragments['select'][]      = "pm.mid";
@@ -903,7 +902,9 @@
   $fragments['query_args']['where'][]  = $pmid;
   $fragments['where'][]       = 'pmi.uid = %d';
   $fragments['query_args']['where'][]  = $account->uid;
+  $fragments['order_by'][]  = 'pmi.is_new DESC LIMIT 1';
 }
+
 /**
  * Query definition to load messages of one or multiple threads.
  *

