Index: realname_theme.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/realname/realname_theme.inc,v
retrieving revision 1.2.4.9
diff -u -r1.2.4.9 realname_theme.inc
--- realname_theme.inc	6 Nov 2008 16:29:05 -0000	1.2.4.9
+++ realname_theme.inc	10 Nov 2008 21:55:32 -0000
@@ -18,13 +18,20 @@
  *   suggests that this is a site user. Otherwise, only the username is returned.
  */
 function phptemplate_username($object) {
-  // If we have a user id but no realname, then make one.
-  if ($object->uid && !$object->realname && user_access('use realname')) {
-    $object->realname = realname_make_name($object);
+  // If the user has a nickname defined and wants to use that
+  $user = user_load(array(uid => $object->uid));
+  if ($user->profile_show_nickname && !empty($user->profile_nickname)) {
+    $object->realname = $user->profile_nickname;
+  }
+  else {
+    // If we have a user id but no realname, then make one.
+    if ($object->uid && !$object->realname && user_access('use realname')) {
+      $object->realname = realname_make_name($object);
+    }
   }
 
-  if ($object->uid && $object->realname) {
-    // Shorten the name when it is too long or it will break many tables.
+  // Shorten the name when it is too long or it will break many tables.
+  if ($object->uid && $object->realname) {  
     if (drupal_strlen($object->realname) > 25) {
       $name = drupal_substr($object->realname, 0, 20) .'...';
     }

