Could be able this Module display the sender's name as an option? It could be usefull, I think.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave.Ingram’s picture

I had that thought as well at one point. Currently it shows the subject of the message and then the first part of the body of the message (or the whole thing, if that's short enough.) What would make the most sense to you? to show the Name and Body? or the Name and Subject? ...I think all three might get a bit too cluttered.

rajo’s picture

My priorities:

Name and Subject and Body
Name and Body
Subject and Body
Name and Subject

In any case, it's Great module.

igorik’s picture

Hi, i subscribe this, i am missing sender's name. Maybe there could be in module settings checkboxes where admin check which informations he want's to show in pgrowl.

Dave.Ingram’s picture

Title: Sender's name » Add Token support to pmgrowl
Version: 6.x-1.1-alpha1 » 6.x-1.1-alpha2
Component: User interface » Code
Assigned: rajo » Unassigned
Priority: Minor » Normal

What makes the most sense here is that we add token support to the subject and message string, making sure tokens are available for sender's name, message, subject, maybe receiver's name as well, then everyone can customize the output exactly as they see fit. I won't have time to work on this immediately, but I'd like to see this feature get in, so if anyone would like to take this on and submit a patch, then I'll gladly review it. Otherwise, I'll work on this as soon as I can free up some time.

George2’s picture

well, realname may add a real name token. not tested. however, after discussion with dave, if privatemsg could add tokens, then it would make this so much easier, and much more future compatible with other modules:

http://drupal.org/node/511796

George2’s picture

also, by not doing "select *" in the _json db query, and instead just grabbing the messageid (mid), and then using _privatemsg_load, a whole load of user data, and message data is available for processing... working on a solution atm

George2’s picture

FileSize
15.67 KB

ok, so this is an example of what i've knocked together. i've added two theme functions, one for the alert subject, and one for the alert body.

in this example the subject doesn't have the message subject, but just a string, and the user name, and the body has the avatar, and a trimmed message body. of course user pictures have to be enabled and imagecache enabled. so, either options could be added to pmgrowl to enable the avatar and what imagecache preset to use, or a basic body template function can be provided, with a note of an example template function override in the docs.

no tokens, but template functions you can override. think it's good enough? it's workable with some css magic!

here are the template functions:

function theme_pmgrowl_alert_body($msg){
  $body = theme('imagecache', 'userprofile_thumb', $msg['user']->picture);
  $body .= check_markup(truncate_utf8($msg['body'], 200, FALSE, TRUE));
  $body .= '<p>'. l(t('Open & Reply'), 'messages/view/'. $msg['mid']) . ' | '. l(t('View All'), 'messages') .'</p>';
  return $body;
}

function theme_pmgrowl_alert_subject($msg){
  return t('New message from @user', array('@user' => $msg['user']->name));
}

i guess that's going to be easy to work with!

gwen’s picture

Status: Active » Needs review
FileSize
7.47 KB

I wanted similar functionality to this and liked George2's approach, so attached is a patch expanding the work from the comments above. In addition to the 2 modified theme functions:
* setting to make user picture optional
* setting to choose which imagecache size to use for pics
* theme functions for the 'new message' subject and body
* simple css file

My work was against privatemsg version 6.x-1.0-rc2. From George2's comments, it sounds like things may have changed from an earlier version b/c I found that _privatemsg_load() did not return any extra information useful for themeing. I instead grabbed the relevant user info by doing a user_load() using the message author's uid.

pheraph’s picture

Any chance to port the patch to the latest version?

Witch’s picture

hi gwen, i will test your patch right now :)

Witch’s picture

gwen, your patch is awesome. Everything works fine. great work. Thank you for this.

Did you already look on this issue? Maybe you can solve this! http://drupal.org/node/573906

Dave.Ingram’s picture

Hi everyone, sorry to be gone for so long.. who all has tested this patch? can it be considered RTBC? George2, have you tried the latest patch?

Thanks again everyone.

MichaelP’s picture

Nice module, nice patch! Just installed, will report back on testing issues.

Thanks all.

Babalu’s picture

patch works great
but when i'm not check my settings after patching it shows me null null in the message notification

Witch’s picture

Will this patch ever be commited? I used in further versions and it worked very great but now i have to upgrade to latest version.

Any ideas how to get imagecache presets into to latest version?

Greetings

Tamela’s picture

Was this added to the most recent version? I could really use this. The messaging become so confusing if you have more than one person sending you a message at one time because you can't tell who it's from.

I've never been able to patch so I'm eagerly waiting for it to be in an updated version.

Thanks!

doitDave’s picture

Hey, that patch committed would be a good base for some further extensions I have now added for my "home use". Shouldn't it be released after now more than a year? :-)

Berdir’s picture

Version: 6.x-1.1-alpha2 » 6.x-2.x-dev
Status: Needs review » Needs work

Because the patch doesn't apply anymore. Help to re-roll is welcome.

+++ pmgrowl.module	20 Aug 2009 21:56:32 -0000
@@ -87,23 +118,25 @@ function pmgrowl_json() {
   // for every message that comes back
   while ($row = db_fetch_object($result)) {
     // check the operating mode, and return a message accordingly
     if(variable_get('pmgrowl_operating_mode', 0) == 0) {
-        $row->body = check_markup(truncate_utf8($row->body, 400, FALSE, TRUE));
-        $row->body .= '<p>'. l(t('Open & Reply'), 'messages/view/'. $row->thread_id);
-        $row->body .= ' | '. l(t('View All'), 'messages') .'</p>';
-        $data[] = $row;
+      $author = user_load($row->author);
+      $message = new StdClass();
+      $message->mid = $row->mid;
+      $message->body = theme('pmgrowl_alert_individual_body', $row, $author);
+      $message->subject = theme('pmgrowl_alert_individual_subject', $row, $author);
+      $data[] = $message;
     } else {
-      $message['subject'] = 'You have Mail!';
-      $message['body'] = 'You have '. l(t('unread messages'), 'messages');
+      $message['subject'] = theme('pmgrowl_alert_new_msg_subject', $row);
+      $message['body'] = theme('pmgrowl_alert_new_msg_body', $row);
       $data[0] = $message;

We should probably rework this part and use privatemsg_message_load_multiple() to load all messages and then just call the theme functions on it. This also means that the query can be simplified a bit to only return mid's.

+++ pmgrowl.module	20 Aug 2009 21:56:32 -0000
@@ -138,21 +171,92 @@ function pmgrowl_admin_settings() {
+  $body .= check_markup(truncate_utf8($msg->body, 200, FALSE, TRUE));

This needs to be updated to use the correct format for that message. Note that the current code does that already, but in a different place.

+++ pmgrowl.module	20 Aug 2009 21:56:32 -0000
@@ -87,23 +118,25 @@ function pmgrowl_json() {
   while ($row = db_fetch_object($result)) {
     // check the operating mode, and return a message accordingly
     if(variable_get('pmgrowl_operating_mode', 0) == 0) {
-        $row->body = check_markup(truncate_utf8($row->body, 400, FALSE, TRUE));
-        $row->body .= '<p>'. l(t('Open & Reply'), 'messages/view/'. $row->thread_id);
-        $row->body .= ' | '. l(t('View All'), 'messages') .'</p>';
-        $data[] = $row;
+      $author = user_load($row->author);
+      $message = new StdClass();
+      $message->mid = $row->mid;
+      $message->body = theme('pmgrowl_alert_individual_body', $row, $author);
+      $message->subject = theme('pmgrowl_alert_individual_subject', $row, $author);
+      $data[] = $message;

The whole thing should be updated to use privatemsg_message_load_multiple() so that all information of the message is available to the theme function. Also, the query function can the be simplified to use return message id's.

+++ pmgrowl.module	20 Aug 2009 21:56:32 -0000
@@ -138,21 +171,92 @@ function pmgrowl_admin_settings() {
+ * This function themes out the individual message alert body

Needs an ending point (same for other theme functions)

+++ pmgrowl.module	20 Aug 2009 21:56:32 -0000
@@ -138,21 +171,92 @@ function pmgrowl_admin_settings() {
+  $body .= check_markup(truncate_utf8($msg->body, 200, FALSE, TRUE));

Note that privatemsg now supports different formats, this function must use the correct one. Note that the current code in pmgrowl_json() already does this, the code can be taken from there.

+++ pmgrowl.module	20 Aug 2009 21:56:32 -0000
@@ -138,21 +171,92 @@ function pmgrowl_admin_settings() {
+  $output .= t('New message from @user', array('@user' => $author->name));

This should use theme('username', $author) (and !user instead of @user) so that it works together with realname.module.

+++ pmgrowl.module	20 Aug 2009 21:56:32 -0000
@@ -138,21 +171,92 @@ function pmgrowl_admin_settings() {
+  $output = '';
+  $output .= t('You have Mail!');
+  return $output;

This can easily be written in a single line :)

+++ pmgrowl.module	20 Aug 2009 21:56:32 -0000
@@ -138,21 +171,92 @@ function pmgrowl_admin_settings() {
+  $output .= t('You have !msgs', array('!msgs' => l(t('unread messages'), 'messages')));

This should use format_plural() to provide a version for single and multiple new messages. Also, it is common for such strings to use something like unread messages" to provide a bit more context to the person that is translating this and make it possible to translate it into RTL languages.

Powered by Dreditor.

Berdir’s picture

Title: Add Token support to pmgrowl » Theme functions for notifications
YK85’s picture

subscribing

gorgo’s picture

Does anybody have a working patch for version 2.x?

Berdir’s picture

Status: Needs work » Needs review
FileSize
7.52 KB

Attaching a revised patch for 6.x-2.x-dev.

Fixes the issues I mentioned above and also uses improved strings and makes the author clickable.

Please test, especially the imagecache part, I don't have that configured locally.

gorgo’s picture

Thanks Berdir!
The patch DOES work for me.
There was one minor problem, that the image goes beyond the black notification area. I easily fixed it by adding this to the new css file:

.pmgrowl-body {
overflow:hidden;
}

I don't know how to write patches myself (yet) so not sure how to add this to your patch.

apart from that it seems to work as expected...

Berdir’s picture

Thanks for testing!

Can you provide a before/after screenshot with your change?

Berdir’s picture

Oh, and regarding patch creation, see http://drupal.org/patch/create. But don't worry, I'll include it in the patch myself...

gorgo’s picture

FileSize
24.38 KB
23.69 KB

Sure man!
Pics attached, and thanks for the link. it's about time i learn how to deal with patches properly. still applying them manually...

Berdir’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev
Status: Needs review » Patch (to be ported)

Commited to 6.x-1.x and 6.x-2.x.

Will port to 7.x-1.x soon.

Berdir’s picture

Version: 7.x-1.x-dev » 6.x-2.x-dev
Status: Patch (to be ported) » Needs review

Ported to 7.x. Note that it needs #1021564: Allow to set image style when using theme('user_picture') for the image style selector to work in Drupal 7.

Berdir’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.