Author Topic: Grabbing Message UID for Plug-in When Message Displayed  (Read 7908 times)

Offline LG73

  • Newbie
  • *
  • Posts: 5
    • http://www.LG73.com/
Grabbing Message UID for Plug-in When Message Displayed
« on: July 29, 2010, 12:48:06 AM »
Hello,

My apologies if this is something too basic to be asking. I'm developing a set of plug-ins that allow the user to rank a message. I have three plug-ins that create three buttons for 3 different ranks. That part works great and the rank is stored in an SQL table with the user_id and the message uid.

The problem I'm having is with another plug-in to show the rank for a message already rated by the user so they can see what they did. I've tried various hooks to get the uid so I can use it for the SQL query but the solution evades me.

If you can provide example code and instructions that would be greatly appreciated. I need the result to be displayed when a message is viewed.

I suspect it's probably a combination of code for both the javascript and php files in the plug-in directory. Thanks in advance for your assistance!


Regards,
Phil in Vancouver

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,882
    • SKaero - Custom Roundcube development
Grabbing Message UID for Plug-in When Message Displayed
« Reply #1 on: July 29, 2010, 03:00:52 AM »
You would use the message_read hook to the the message uid.

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,856
Grabbing Message UID for Plug-in When Message Displayed
« Reply #2 on: July 29, 2010, 03:03:21 AM »
Take a look at the javascript event hook `insertrow` that passes the UID of the row as the first parameter, and with a tiny bit of parsing you get the message UID. You could trigger an AJAX call on that hook which goes and gets the ranking information and then adds it to the screen.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and moreā€¦

Offline corbosman

  • Sr. Member
  • ****
  • Posts: 260
Grabbing Message UID for Plug-in When Message Displayed
« Reply #3 on: July 29, 2010, 04:19:02 AM »
Have a look at my message_highlight plugin. It does exactly what you're describing only it tags colors for messages. You need a recent SVN for this as Alec added some code for me so this would actually work.

Offline LG73

  • Newbie
  • *
  • Posts: 5
    • http://www.LG73.com/
Grabbing Message UID for Plug-in When Message Displayed
« Reply #4 on: July 29, 2010, 07:59:31 AM »
Hi Cor,

That message_highlight approach would be my first choice for providing feedback to the user on how they ranked the message. I switched from the 0.4 beta to r3838 and your plug-in works. It looks great. I see you are using a new hook called messages_list.

I'm still confused on how I would be getting the uid of the message so I could set the message highlight colour according to the stored rank for the message. I've made attempts with the message_read hook on the PHP side and the insertrow event listener on the javascript side but I'm doing something wrong.

I see you are using the insertrow event listener in message_highlight.js. I keep trying to extract the UID from that but each thing I've done breaks the message highlighting.

Once I do get the UID I'm assuming I'd be using rcmail.http_post to pass it back to the main php script.

I want to base this on your existing message_highlight script replacing the prefs based colour choices with 3 fixed colour choices based on the user's message ranking. Any further tips on how to make that happen including code samples would be greatly appreciated. It's now almost 5 a.m. here and I feel like I'm very close to finding a way to make this work.

Thank you for your kind assistance.

Regards,
Phil

Offline corbosman

  • Sr. Member
  • ****
  • Posts: 260
Grabbing Message UID for Plug-in When Message Displayed
« Reply #5 on: July 29, 2010, 05:57:23 PM »
You have to do the same I did. Use the messages_list hook. Loop over all messages there, uid is in the arrays you get, and return the extra_flags array for each message you need to color. It's basically the same as im doing.

You dont need to change much at all regarding the eventrow listener.

Offline LG73

  • Newbie
  • *
  • Posts: 5
    • http://www.LG73.com/
Grabbing Message UID for Plug-in When Message Displayed
« Reply #6 on: July 30, 2010, 04:22:20 AM »
Hi Cor,

I think I'm down to one missing line of code to make this work. I put my SQL query inside function mh_highlight ($p) inside the foreach($p['messages'] as $message loop. I still can't get the uid value. I've tried what I thought would be the obvious choices like $uids = $p['uids']; and many other variations but nothing I try works. I can manually set the highlight colour for $color and that works so I now know how to do the highlight colours based on the query results.

Any chance of a piece of sample code showing how to get the uid out of the messages_list hook's array from inside that loop in the mh_highlight function?

Thanks in advance and sorry again if what I'm asking for should be obvious.


Regards,
Phil

Offline corbosman

  • Sr. Member
  • ****
  • Posts: 260
Grabbing Message UID for Plug-in When Message Displayed
« Reply #7 on: July 30, 2010, 04:46:17 AM »
This is how you loop over the messages array and get the uid for each msg:


    
// loop over all messages and add highlight color to each message
    
foreach($p['messages'] as $message) {
      
$uid $message['uid'];

      
// do something to see if this uid needs a color or not..

    
}

Offline LG73

  • Newbie
  • *
  • Posts: 5
    • http://www.LG73.com/
Grabbing Message UID for Plug-in When Message Displayed
« Reply #8 on: July 30, 2010, 05:01:45 AM »
Hi Cor,

$uid = $message['uid']; was one of the first methods I had attempted before. I tried it again as you recommended but with that line of code in place instead of a list of messages I get an error message: "Server Error! (Internal Server Error)"

If I comment out that line then the messages display normally (but without any highlighting). is it possible the uid is missing from the messages_list hook?


Regards,
Phil

Offline corbosman

  • Sr. Member
  • ****
  • Posts: 260
Grabbing Message UID for Plug-in When Message Displayed
« Reply #9 on: July 30, 2010, 05:07:30 AM »
instead of $message['uid'] use $message->uid

Cor

Offline LG73

  • Newbie
  • *
  • Posts: 5
    • http://www.LG73.com/
Grabbing Message UID for Plug-in When Message Displayed
« Reply #10 on: July 30, 2010, 05:11:58 AM »
Hi Cor,

Awesome, that works! Thank you very much for your help!


Regards,
Phil