1

Anyone knows how to display a list of all messages that two users had shared using the Privatemsg module for Drupal 7? Sort of a history of the conversation between the two users in a block or in a template.tpl.php?

Any help please.

2
  • I succeeded in doing this by creating a function in my custom module, passing two arguments in it, the sender id and the recipient id. Then I call the function anywhere. Here is the function I created: function get_message_history($uid, $recipient){ $query = db_query("SELECT * FROM pm_index, pm_message WHERE ((pm_index.recipient = $uid AND pm_message.author = $recipient) OR (pm_index.recipient = $recipient AND pm_message.author = $uid)) AND pm_index.mid = pm_message.mid ORDER BY pm_message.timestamp DESC"); $messages = $query->fetchAll(); return $messages; } – IA Varsally Jun 10 '13 at 11:00
  • You should enter this comment as a self-answer, as it may help others in the future. – Free Radical Jun 3 '14 at 4:14
1

The OP succeeded in doing this by creating a helper function in a custom module.

The function accepts two arguments, the sender uid and the recipient uid. It returns the list of messages.

Then one can call this function from anywhere to get the required list of messages.

Here is the function the OP created:

function get_message_history($sender_uid, $recipient_uid) {
  $query = db_query("SELECT * FROM pm_index, pm_message
    WHERE ((pm_index.recipient = $sender_uid AND pm_message.author = $recipient_uid)
      OR (pm_index.recipient = $recipient_uid AND pm_message.author = $sender_uid))
      AND pm_index.mid = pm_message.mid
    ORDER BY pm_message.timestamp DESC");
  $messages = $query->fetchAll();
  return $messages;
}
1
  • 1
    OP hasn't been seen since July 2013. Since SE protocol is to delete question with no answers and only 1 comment after 365 days (that's 7 days from now), and this may be useful to others, I post the OPs self answer as a full answer (mods: feel free to assign this answer to the Community User). – Free Radical Jun 3 '14 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.