? 430948.fallback.patch
? privatemsg_fix_is_new_2.patch
? privatemsg_fix_is_new_3.patch
? privatemsg_fix_is_new_4.patch
? privatemsg_fix_is_new_5.patch
? privatemsg_strong.patch
Index: privatemsg.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/privatemsg.install,v
retrieving revision 1.5.2.4.2.11.2.9
diff -u -r1.5.2.4.2.11.2.9 privatemsg.install
--- privatemsg.install	8 Jun 2009 15:10:08 -0000	1.5.2.4.2.11.2.9
+++ privatemsg.install	1 Jul 2009 22:12:01 -0000
@@ -112,33 +112,6 @@
   drupal_uninstall_schema('privatemsg');
 }
 
-function privatemsg_update_6001() {
-  $ret = array();
-
-  if (!db_column_exists('pm_index', 'is_new')) {
-
-    if (db_column_exists('pm_index', 'new')) {
-      $old_column = 'new';
-    }
-    elseif (db_column_exists('pm_index', 'new_flag')) {
-      $old_column = 'new_flag';
-    }
-    else {
-      return $ret;
-    }
-
-    db_drop_index($ret, 'pm_index', $old_column);
-    db_change_field($ret, 'pm_index', $old_column, 'is_new', array(
-          'description'   => 'Whether the user has read this message',
-          'type'          => 'int',
-          'default'       => 1,
-          'not null'      => TRUE,
-          'unsigned'      => TRUE));
-    db_add_index($ret, 'pm_index', 'is_new', array('mid', 'uid', 'is_new'));
-  }
-
-  return $ret;
-}
 
 function privatemsg_update_6000() {
   // Give update unlimited time to complete.
@@ -393,6 +366,34 @@
   return $ret;
 }
 
+function privatemsg_update_6001() {
+  $ret = array();
+
+  if (!db_column_exists('pm_index', 'is_new')) {
+
+    if (db_column_exists('pm_index', 'new')) {
+      $old_column = 'new';
+    }
+    elseif (db_column_exists('pm_index', 'new_flag')) {
+      $old_column = 'new_flag';
+    }
+    else {
+      return $ret;
+    }
+
+    db_drop_index($ret, 'pm_index', $old_column);
+    db_change_field($ret, 'pm_index', $old_column, 'is_new', array(
+          'description'   => 'Whether the user has read this message',
+          'type'          => 'int',
+          'default'       => 1,
+          'not null'      => TRUE,
+          'unsigned'      => TRUE));
+    db_add_index($ret, 'pm_index', 'is_new', array('mid', 'uid', 'is_new'));
+  }
+
+  return $ret;
+}
+
 function privatemsg_update_6002() {
   $ret = array();
   // update_sql does not support parameters, we need to use db_query
@@ -400,4 +401,20 @@
   $result = db_query($sql, BLOCK_NO_CACHE);
   $ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql));
   return $ret;
+}
+
+/**
+ * Update function to resolve "forever new" messages
+ * as described in http://drupal.org/node/490650
+ */
+function privatemsg_update_6003() {
+  $ret = array();
+  // Find messages that have aformentioned problem
+  $sql = "SELECT DISTINCT p1.mid, p1.uid FROM pm_index p1 INNER JOIN pm_index p2 ON p1.thread_id = p2.thread_id AND p1.mid = p2.mid INNER JOIN pm_message pm ON p1.uid = pm.author AND p2.uid = pm.author WHERE p1.is_new != p2.is_new";
+  $result = db_query($sql);
+  while($row = db_fetch_object($result)) {
+      privatemsg_message_change_status($row->mid, PRIVATEMSG_READ, $row );
+  }
+  $ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql));
+  return $ret;
 }
\ No newline at end of file
Index: privatemsg.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/privatemsg.module,v
retrieving revision 1.70.2.30.2.91.2.55
diff -u -r1.70.2.30.2.91.2.55 privatemsg.module
--- privatemsg.module	1 Jul 2009 18:19:29 -0000	1.70.2.30.2.91.2.55
+++ privatemsg.module	1 Jul 2009 22:12:01 -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'; // We only want the distinct number of messages in this thread.
   }
   if (in_array('participants', $fields)) {
     // Query for a string with uid's, for example "1,6,7". This needs a subquery on PostgreSQL.
@@ -1364,8 +1364,12 @@
 
     db_query($query, $mid, $message['thread_id'], $recipient->uid, 1);
   }
+
+  // When author is also the recipient, we want to set message to UNREAD. all other times his message is set to read
+  $is_new = isset($message['recipients'][$message['author']->uid]) ? 1 : 0;
+
   // Also add a record for tha author to the pm_index table - set  column "new" to 0.
-  db_query($query, $mid, $message['thread_id'], $message['author']->uid, 0);
+  db_query($query, $mid, $message['thread_id'], $message['author']->uid, $is_new);
 
   module_invoke_all('privatemsg_message_insert', $message);
 
