First off, this module is AWESOME! Thanks so much for the work put into making it. It was exactly what I was looking for.

My only question is if there is a way to add a timestamp for each message? Ie, I send a message at 3:42 pm and to the right of the message, across from my name, it posts '3:42 pm'. Is there a way to configure that functionality with the present module? And if not, any pointers in the right direction on how I might go about coding that?

Thanks a bunch for the help!

Comments

pahariwalla’s picture

Issue tags: +theming

The theming of messages is performed by the function theme_im_msgs($msgs, $other_name) in im.moduke

you can override this with any of the normal Drupal theme overide methods such as a function in your theme's template.php

The $msgs array holds a single message and contain the following fields:

      'mid' => autoincrement message ID
      'other_name' => name of the person you are talking with
      'suid' => uid of the sender of the message
      'ruid' => uid of teh recipient of the message
      'sname' => name of the sender
      'rname' => name of the recipient
      'msg' => the message text
      'sent_time' => timestamp of when the message was sent, formatted 'Y-m-d H:i:s'

The current function looks like this:

function theme_im_msgs($msgs, $other_name) {
  global $user;
	
  $uid = $user->uid;
  
  $output = '';
  if (sizeof($msgs) > 0) {
    foreach ($msgs as $key => $msg) {
      $output .= '<span class="im-console-msg-name">' ;
      
      if ($user->uid == $msg['suid']) {
        $output .= t('Me') .': </span>';  
        $output .= '<span class="im-console-my-msgtext">';
      }
      else {
        $output .= $msg['sname'] .': </span>';  
        $output .= '<span class="im-console-other-msgtext">';
      }
      $output .= check_plain($msg['msg']);
      $output .= '</span><br/>';
    }
  }
  return $output;
}

If you wanted the datetime to appear at the beginning of each message, you might add this modified function to your theme's template.php

function phptemplate_im_msgs($msgs, $other_name) {
  global $user;
  
  $uid = $user->uid;
  
  $output = '';
  if (sizeof($msgs) > 0) {
    foreach ($msgs as $key => $msg) {
      $output .= '<span class="im-console-msg-datetime">' ;
      $output .= $msg['sent_time'];
      $output .= ' </span>';

      $output .= '<span class="im-console-msg-name">' ;
      
      if ($user->uid == $msg['suid']) {
        $output .= t('Me') .': </span>';  
        $output .= '<span class="im-console-my-msgtext">';
      }
      else {
        $output .= $msg['sname'] .': </span>';  
        $output .= '<span class="im-console-other-msgtext">';
      }
      $output .= check_plain($msg['msg']);
      $output .= '</span><br/>';
    }
  }
  return $output;
}

If you want it to appear on the right, justified, then you probably want to use tables or divs with css.

Hope this helps.

Dain Berrett’s picture

Wow, thanks so much! That worked perfect, it looks great.

I guess one last question I have: is there a way to change the 'sent-time' output from 'Y-m-d H:i:s' to 'H:i a', so that I can get a shorter timestamp like 4:20 pm?

Thanks!

pahariwalla’s picture

Yeah ... i should have put the formatting in a themable function ... but you can convert the formatted time string back to an integer with the strtotime() function and then reformat it as you want like so:

      $output .= date(strtotime($msg['sent_time']), 'H:i a');
Dain Berrett’s picture

Status: Active » Closed (fixed)

Once again, you rock! Thanks so much for the help. :)