? .cvsignore
? new_thread_uid_bug.patch
Index: privatemsg.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/privatemsg/privatemsg.module,v
retrieving revision 1.70.2.30.2.91.2.101
diff -u -p -r1.70.2.30.2.91.2.101 privatemsg.module
--- privatemsg.module	26 Nov 2009 18:42:54 -0000	1.70.2.30.2.91.2.101
+++ privatemsg.module	29 Nov 2009 21:52:04 -0000
@@ -1599,7 +1599,11 @@ function privatemsg_new_thread($recipien
   $message = array();
   $message['subject'] = $subject;
   $message['body'] = $body;
-  $message['recipients'] = $recipients;
+  // Make sure that recipients are keyed by user id and are not added
+  // multiple times.
+  foreach ($recipients as $recipient) {
+    $message['recipients'][$recipient->uid] = $recipient;
+  }
 
   // Set custom options, if any.
   if (!empty($options)) {
Index: tests/privatemsgapi.test
===================================================================
RCS file: /cvs/drupal/contributions/modules/privatemsg/tests/Attic/privatemsgapi.test,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 privatemsgapi.test
--- tests/privatemsgapi.test	19 Nov 2009 21:35:24 -0000	1.1.2.4
+++ tests/privatemsgapi.test	29 Nov 2009 21:52:04 -0000
@@ -32,7 +32,7 @@ class PrivatemsgAPITestCase extends Drup
   }
 
   function testPrivatemsgApiNewThread() {
-    $author     = $this->drupalCreateUser(array('write privatemsg'));
+    $author     = $this->drupalCreateUser(array('write privatemsg', 'read privatemsg'));
     $recipient1  = $this->drupalCreateUser(array('read privatemsg'));
     $recipient2  = $this->drupalCreateUser(array('read privatemsg'));
     $recipient3  = $this->drupalCreateUser(array('read privatemsg'));
@@ -70,6 +70,14 @@ class PrivatemsgAPITestCase extends Drup
     $this->assertEqual($errormessage, $resultf4['messages']['error'][0], t('User is not allowed to use the specified input format.'));
     $message = $this->getMessageFromSubject('input filter not allowed');
     $this->assertTrue(empty($message), 'Message was not saved in database');
+
+    // Send a message through the api to the same user and check if it marked
+    // as new.
+    privatemsg_new_thread(array($author), $subject = $this->randomString(10), $this->randomString(20), array('author' => $author));
+    $this->drupalLogin($author);
+    $this->drupalGet('messages');
+    $this->clickLink($subject);
+    $this->assertText(t('New'), t('Message is marked as new'));
   }
 
   function getMessageFromSubject($subject) {
