Index: privatemsg.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/privatemsg.module,v
retrieving revision 1.70.2.30.2.91.2.13
diff -u -r1.70.2.30.2.91.2.13 privatemsg.module
--- privatemsg.module	27 Jan 2009 16:55:18 -0000	1.70.2.30.2.91.2.13
+++ privatemsg.module	2 Feb 2009 03:27:26 -0000
@@ -317,11 +317,11 @@
 function privatemsg_list_messages($account) {
   switch (arg(1)) {
     case 'sent':
-      $query = _privatemsg_assemble_query('privatemsg_list_sent', $account);
+      $query = _privatemsg_assemble_query('list_sent', $account);
       break;
     case 'inbox':
     default:
-      $query = _privatemsg_assemble_query('privatemsg_list', $account);
+      $query = _privatemsg_assemble_query('list', $account);
   }
   $result = pager_query($query['query'], variable_get('privatemsg_per_page', 25), 0, $query['count']);
 
@@ -412,7 +412,7 @@
     $account = $user;
   }
   if ( !isset($counts[$account->uid])) {
-    $query = _privatemsg_assemble_query('privatemsg_unread_count', $account);
+    $query = _privatemsg_assemble_query('unread_count', $account);
     $counts[$account->uid] = db_result(db_query($query['query']));
   }
   return $counts[$account->uid];
@@ -462,7 +462,7 @@
   $output = '';
 
   // Load the list of participants.
-  $query = _privatemsg_assemble_query('privatemsg_participants', $thread_id);
+  $query = _privatemsg_assemble_query('participants', $thread_id);
   $participants = db_query($query['query']);
   while ($result = db_fetch_object($participants)) {
     $message['participants'][] = user_load($result->uid);
@@ -471,7 +471,7 @@
   $content['participants']['#weight'] = -5;
 
   // Load the messages.
-  $query = _privatemsg_assemble_query('privatemsg_messages', $thread_id, $user->uid);
+  $query = _privatemsg_assemble_query('messages', $thread_id, $user->uid);
   $conversation = db_query($query['query']);
   $message_count = 0;
   while ($result = db_fetch_array($conversation)) {
@@ -718,7 +718,7 @@
   $form_state['rebuild'] = TRUE; //this forces our form to be rebuilt instead of being submitted.
 }
 
-function privatemsg_privatemsg_list_sent_alter(&$fragments, $account) {
+function privatemsg_sql_list_sent(&$fragments, $account) {
   $fragments['primary_table'] = '{pm_message} pm';
 
   $fragments['select'][]      = 'pmi.thread_id';
@@ -760,7 +760,7 @@
   $fragments['order_by'][]  = $order .' '. $sort;
 }
 
-function privatemsg_privatemsg_list_alter(&$fragments, $account) {
+function privatemsg_sql_list(&$fragments, $account) {
   $fragments['primary_table'] = '{pm_message} pm';
 
   $fragments['select'][]      = 'pmi.thread_id';
@@ -780,7 +780,7 @@
   $fragments['select'][]      = 'MIN(pm.timestamp) as thread_started';
   $fragments['select'][]      = 'MAX(pmi.is_new) as is_new';
   // pm_index needs to be the first join.
-  array_unshift($fragments['inner_join'], 'INNER JOIN {pm_index} pmi ON pm.mid = pmi.mid');
+  $fragments['inner_join'][]  = 'INNER JOIN {pm_index} pmi ON pm.mid = pmi.mid';
   $fragments['where'][]       = 'pmi.uid = %d';
   $fragments['query_args'][]  = $account->uid;
   $fragments['where'][]       = 'pmi.deleted = 0';
@@ -800,7 +800,7 @@
 
 }
 
-function privatemsg_privatemsg_load_alter(&$fragments, $pmid, $uid) {
+function privatemsg_sql_load(&$fragments, $pmid, $uid) {
 //  drupal_set_message('<pre>'. print_r(func_get_args(), 1) . '</pre>');
   $fragments['primary_table'] = '{pm_message} pm'; // Our primary table
 
@@ -818,7 +818,7 @@
   $fragments['query_args'][]  = $uid;
 }
 
-function privatemsg_privatemsg_messages_alter(&$fragments, $thread_id, $uid) {
+function privatemsg_sql_messages(&$fragments, $thread_id, $uid) {
   $fragments['primary_table'] = '{pm_index} pmi';
 
   $fragments['select'][]      = 'DISTINCT(pmi.mid) as mid';
@@ -830,7 +830,7 @@
   $fragments['order_by'][]    = 'pmi.mid ASC';
 }
 
-function privatemsg_privatemsg_participants_alter(&$fragments, $thread_id) {
+function privatemsg_sql_participants(&$fragments, $thread_id) {
   $fragments['primary_table'] = '{pm_index} pmi';
 
   $fragments['select'][]      = 'DISTINCT(pmi.uid) as uid';
@@ -839,7 +839,7 @@
 }
 
 
-function privatemsg_privatemsg_unread_count_alter(&$fragments, $account) {
+function privatemsg_sql_unread_count(&$fragments, $account) {
   $fragments['primary_table'] = '{pm_index} pmi';
 
   $fragments['select'][]      = 'COUNT(DISTINCT thread_id) as unread_count';
@@ -1009,7 +1009,7 @@
         global $user;
         $subject = db_result(db_query('SELECT subject FROM {pm_message} WHERE mid = %d', arg(2)));
         $thread = db_result(db_query('SELECT thread_id FROM {pm_index} WHERE mid = %d', arg(2)));
-        $query = _privatemsg_assemble_query('privatemsg_participants', $thread);
+        $query = _privatemsg_assemble_query('participants', $thread);
         $participants = db_query($query['query']);
         $usercount = 0;
         while ($result = db_fetch_object($participants)) {
Index: privatemsg_filter/privatemsg_filter.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/privatemsg_filter/privatemsg_filter.module,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 privatemsg_filter.module
--- privatemsg_filter/privatemsg_filter.module	23 Dec 2008 16:46:13 -0000	1.1.2.2
+++ privatemsg_filter/privatemsg_filter.module	2 Feb 2009 03:06:07 -0000
@@ -392,7 +392,7 @@
 /**
  * Hook into the query builder to add the tagging info to the correct query
  */
-function privatemsg_filter_privatemsg_list_alter(&$fragments) {
+function privatemsg_filter_privatemsg_sql_list_alter(&$fragments) {
   // Filter the message listing by any set tags.
   if ($filter = privatemsg_filter_get_filter(user_load($fragments['query_args'][0]))) {
 
Index: privatemsgapi/privatemsgapi.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/privatemsg/privatemsgapi/privatemsgapi.inc,v
retrieving revision 1.8.2.1
diff -u -r1.8.2.1 privatemsgapi.inc
--- privatemsgapi/privatemsgapi.inc	26 Jan 2009 19:53:27 -0000	1.8.2.1
+++ privatemsgapi/privatemsgapi.inc	2 Feb 2009 03:24:45 -0000
@@ -67,7 +67,22 @@
   return $message;
 }
 
-function _privatemsg_assemble_query($query_id) {
+function _privatemsg_assemble_query($query) {
+
+  //Modules will be allowed to choose the prefix for the querybuilder, but if there is not one supplied, 'privatemsg' will be taken by default.
+  if (is_array($query)) {
+    $query_id = $query[0];
+    $query_name = $query[1];
+  }
+  else {
+    $query_id = $query;
+    $query_name = 'privatemsg';  
+  }
+  
+  // Some old style queries could be prefixed with 'privatemsg_' - this should account for that.
+  if (substr($query_id, 0, 11) == 'privatemsg_') {
+    $query_id = substr($query_id, 11);
+  }
 
   $SELECT = array();
   $INNER_JOIN = array();
@@ -94,15 +109,21 @@
   unset($args[0]);
   //we do the merge because we call call_user_func_array and not drupal_alter
   //this is necessary because otherwise we would not be able to use $args correctly (otherwise it doesnt unfold)
+  $alterargs = array(&$fragments);
+  $query_function = $query_name .'_sql_'. $query_id;
   if (!empty($args)) {
-     $alterargs = array_merge(array($query_id, &$fragments, ), $args);
-  }
-  else {
-     $alterargs = array($query_id, &$fragments, );
+    $alterargs = array_merge($alterargs, $args);
   }
   /**
    * END: Dynamic arguments
    */
+  if (!function_exists($query_function)) {
+    drupal_set_message(t('Query function %function does not exist', array('%function' => $query_function)), 'error');
+    return FALSE;
+  }
+  call_user_func_array($query_function, $alterargs);
+
+  array_unshift($alterargs, $query_function);
   call_user_func_array('drupal_alter', $alterargs);
 
   $SELECT = $fragments['select'];

