Index: privatemsg.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/privatemsg/privatemsg.module,v
retrieving revision 1.70.2.30.2.91.2.106
diff -u -p -r1.70.2.30.2.91.2.106 privatemsg.module
--- privatemsg.module	2 Jan 2010 09:19:23 -0000	1.70.2.30.2.91.2.106
+++ privatemsg.module	15 Feb 2010 14:31:25 -0000
@@ -285,21 +285,28 @@ function privatemsg_thread_load($thread_
     }
 
     if (!array_key_exists($thread_id, $threads[$account->uid])) {
+      drupal_set_message(t('Attempting to load thread....'));
+      drupal_set_message(t('Active account: %uid => %name', array('%name' => $account->name, '%uid' => $account->uid)));
       // Load the list of participants.
       $query = _privatemsg_assemble_query('participants', $thread_id);
       $participants = db_query($query['query']);
       $thread['participants'] = array();
+      drupal_set_message(t('Loading participants participants....'));
       while ($participant = db_fetch_object($participants)) {
+        drupal_set_message(t('Found participant: %uid => %name', array('%name' => $participant->name, '%uid' => $participant->uid)));
         $thread['participants'][$participant->uid] = $participant;
       }
       $thread['read_all'] = FALSE;
       if (!array_key_exists($account->uid, $thread['participants']) && privatemsg_user_access('read all private messages', $account)) {
+        drupal_set_message('Read all enabled, current account is not a recipient but does have the read all permission.');
         $thread['read_all'] = TRUE;
       }
 
       // Load messages returned by the messages query with privatemsg_message_load_multiple().
+      drupal_set_message('Loading messages....');
       $query = _privatemsg_assemble_query('messages', array($thread_id), $thread['read_all'] ? NULL : $account);
       $thread['message_count'] = $thread['to'] = db_result(db_query($query['count']));
+      drupal_set_message(t('Found %count messages.', array('%count' => $thread['message_count'])));
       $thread['from'] = 1;
       // Check if we need to limit the messages.
       $max_amount = variable_get('privatemsg_view_max_amount', 20);
@@ -313,7 +320,7 @@ function privatemsg_thread_load($thread_
           $start = $thread['message_count'] - (variable_get('privatemsg_view_use_max_as_default', FALSE) ? variable_get('privatemsg_view_default_amount', 10) : variable_get('privatemsg_view_max_amount', 20));
         }
       }
-
+      drupal_set_message(t('Calculating which messages to load based on paging...'));
       if ($start != PRIVATEMSG_UNLIMITED) {
         if ($max_amount == PRIVATEMSG_UNLIMITED) {
           $last_page = 0;
@@ -356,9 +363,11 @@ function privatemsg_thread_load($thread_
         }
         // Visual counts start from 1 instead of zero, so plus one.
         $thread['from'] = $start + 1;
+        drupal_set_message(t('Loading %amount messages, starting with %start', array('%start' => $start, '%amount' => $max_amount)));
         $conversation = db_query_range($query['query'], $start, $max_amount);
       }
       else {
+        drupal_set_message(t('Loading all messages....'));
         $conversation = db_query($query['query']);
       }
       $mids = array();
@@ -366,13 +375,16 @@ function privatemsg_thread_load($thread_
         $mids[] = $result['mid'];
       }
       // Load messages returned by the messages query.
+      drupal_set_message(t('Found mids: %mids', array('%mids' => implode(', ', $mids))));
       $thread['messages'] = privatemsg_message_load_multiple($mids, $thread['read_all'] ? NULL : $account);
+      drupal_set_message(t('Loaded messages: %messages', array('%messages' => print_r($thread['messages'], TRUE))));
 
       // If there are no messages, don't allow access to the thread.
       if (empty($thread['messages'])) {
         $thread = FALSE;
       }
       else {
+        drupal_set_message(t('Thread loaded successfully!'));
         // General data, assume subject is the same for all messages of that thread.
         $thread['user'] = $account;
         $message = current($thread['messages']);
