From 99faa08dc15347a07b06d6e0f0be30e92726bc24 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Sat, 25 Jun 2011 16:25:45 +0200
Subject: [PATCH] Issue #1167362 by Berdir: Added from column including configurable user picture.

---
 privatemsg.admin.inc       |   33 ++++++++++++++++++++++++++-------
 privatemsg.module          |   12 ++++++++++++
 privatemsg.theme.inc       |   23 +++++++++++++++++++++++
 styles/privatemsg-list.css |    9 +++++++++
 4 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/privatemsg.admin.inc b/privatemsg.admin.inc
index 3e1f344..b974f06 100644
--- a/privatemsg.admin.inc
+++ b/privatemsg.admin.inc
@@ -112,13 +112,7 @@ function privatemsg_admin_settings() {
     '#weight' => -5,
   );
 
-  $form['privatemsg_listing']['privatemsg_per_page'] = array(
-    '#type' => 'select',
-    '#title' => t('Threads per page'),
-    '#default_value' => variable_get('privatemsg_per_page', 25),
-    '#options' => drupal_map_assoc(array(10, 25, 50, 75, 100)),
-    '#description' => t('Choose the number of conversations that should be listed per page.'),
-  );
+
 
   $form['privatemsg_listing']['privatemsg_fields'] = array(
     '#type' => 'fieldset',
@@ -152,6 +146,31 @@ function privatemsg_admin_settings() {
     );
   }
 
+  $presets = array('' => t('Default'));
+  if (module_exists('imagecache_profiles')) {
+    foreach (imagecache_presets() as $preset) {
+      $presets[$preset['presetname']] = check_plain($preset['presetname']);
+    }
+  }
+
+  $presets['-disabled-'] = t('- No user picture -');
+
+  $form['privatemsg_listing']['privatemsg_listing_imagecache_preset'] = array(
+    '#type' => 'select',
+    '#title' => t('Profile picture for message listing'),
+    '#default_value' => variable_get('privatemsg_listing_imagecache_preset', ''),
+    '#options' => $presets,
+    '#description' => t("This will set the picture size in the 'From' column in the private message listing. Choose '- No user picture -' to disable the display of the user picture completely."),
+  );
+
+  $form['privatemsg_listing']['privatemsg_per_page'] = array(
+    '#type' => 'select',
+    '#title' => t('Threads per page'),
+    '#default_value' => variable_get('privatemsg_per_page', 25),
+    '#options' => drupal_map_assoc(array(10, 25, 50, 75, 100)),
+    '#description' => t('Choose the number of conversations that should be listed per page.'),
+  );
+
   $form['privatemsg_listing']['privatemsg_url_prefix'] = array(
     '#type' => 'textfield',
     '#title' => t('Base URL path'),
diff --git a/privatemsg.module b/privatemsg.module
index 23810da..f03a294 100644
--- a/privatemsg.module
+++ b/privatemsg.module
@@ -1062,6 +1062,12 @@ function privatemsg_sql_list(&$fragments, $account, $argument = 'list') {
     $fragments['select'][]      = 'MIN(pm.timestamp) as thread_started';
   }
 
+  // Try to figure out last author if enabled.
+  if (in_array('author', $fields)) {
+    $fragments['select'][]      = '(SELECT pma.author FROM {pm_message} pma WHERE pmi.mid = pma.mid AND pma.author <> %d ORDER BY pma.timestamp DESC LIMIT 1) AS author';
+    $fragments['query_args']['select'][] = $account->uid;
+  }
+
   $fragments['inner_join'][]  = 'INNER JOIN {pm_index} pmi ON pm.mid = pmi.mid';
 
   // Only load undeleted messages of the current user and group by thread.
@@ -2956,6 +2962,12 @@ function privatemsg_privatemsg_header_info() {
       'class'   => 'privatemsg-header-threadstarted',
       '#weight'  => -10,
     ),
+    'author' => array(
+      'data' => t('From'),
+      'field' => 'author',
+      'class' => 'privatemsg-header-author',
+      '#weight' => 0,
+    ),
   );
 }
 
diff --git a/privatemsg.theme.inc b/privatemsg.theme.inc
index 4e766ce..5a67b37 100644
--- a/privatemsg.theme.inc
+++ b/privatemsg.theme.inc
@@ -54,6 +54,29 @@ function phptemplate_privatemsg_list_field__participants($thread) {
 }
 
 /**
+ * Theme the last author field.
+ */
+function phptemplate_privatemsg_list_field__author($thread) {
+  if (!empty($thread['author'])) {
+    if ($author = privatemsg_user_load($thread['author'])) {
+      $field = array();
+
+      $preset = variable_get('privatemsg_listing_imagecache_preset', '');
+      if ($preset && $preset != '-disabled-') {
+        $author->imagecache_preset = $preset;
+      }
+      $field['data'] = '';
+      if ($preset != '-disabled-') {
+      $field['data'] = theme('user_picture', $author);
+      }
+      $field['data'] .= privatemsg_recipient_format($author);
+      $field['class'] = 'privatemsg-list-author';
+    }
+    return $field;
+  }
+}
+
+/**
  * Theme the subject of the thread.
  */
 function phptemplate_privatemsg_list_field__subject($thread) {
diff --git a/styles/privatemsg-list.css b/styles/privatemsg-list.css
index 1bdbef6..7147a5e 100644
--- a/styles/privatemsg-list.css
+++ b/styles/privatemsg-list.css
@@ -21,3 +21,12 @@
 form#privatemsg-list div.container-inline * {
   margin: 0 2px;
 }
+
+td.privatemsg-list-author div.picture {
+    float: none;
+    padding-left: 0;
+}
+
+table.privatemsg-list td {
+    vertical-align: top;
+}
-- 
1.7.4.1

