This page explains how to remove all the recipients of the Privatemsg thread so that only the sender is visible in the participants.

I wanted to be able to send messages to multiple people without all those people knowing who else I sent the message to (exactly how BCC works in email).

Berdir the modules maintainer kindly sent along this code:

function yourmodule_privatemsg_sql_participants_alter(&$fragments, $thread_id) {
  global $user;

  // Join table that contains author information.
  $fragments['inner_join'][]  = 'INNER JOIN {pm_message} pm ON (pm.mid = pmi.mid)';

  // Only include the author of the first message of that thread and
  // the current user (needed for permission checks).
  $fragments['where'][] = '(pmi.uid = pm.author AND pmi.mid = pmi.thread_id) OR pmi.uid = %d';
  $fragments['query_args']['where'][] = $user->uid;
}

Which accomplished this perfectly. Thanks Berdir and thanks for this awesome module!

Comments

shklnrj’s picture

Hey i tried to implement the above changes. I went to the privatemsg.api.php folder and pasted the above code as-

function hook_privatemsg_sql_participants_alter(&$fragment, $thread_id) {
global $user;

// Join table that contains author information.
$fragments['inner_join'][] = 'INNER JOIN {pm_message} pm ON (pm.mid = pmi.mid)';

// Only include the author of the first message of that thread and
// the current user (needed for permission checks).
$fragments['where'][] = '(pmi.uid = pm.author AND pmi.mid = pmi.thread_id) OR pmi.uid = %d';
$fragments['query_args']['where'][] = $user->uid;
}

But i am still getting the same view of participants.
Any solutions??

AgaPe’s picture

How about creating you module called for example "your_module" and then

function your_module_privatemsg_sql_participants_alter(&$fragment, $thread_id) {
...
}

moesi_123’s picture

NOP Dont work

shklnrj’s picture

Hey i made my custom module and used the above code for finishing the task. But still it did not work out for me.

iterator’s picture

Don´t work. If you reply to a pm the recipient will always be the author of the first message of that thread also if the author of the first message wants to reply. In that case the author of the first message of that thread would send a message to himself.

andyhu’s picture

It might be useful if we also can do this:
Send each users a separate message thread when there are multiple users in the list. So in each thread there are only two participants: Sender and receiver.

Here is how I did it in the ugly way..(Please don't use it on production site since it's not been tested enough)

/**
 * Implementation of hook_privatemsg_message_presave_alter
 */
function YOUR_MODULE_privatemsg_message_presave_alter(&$message) {
  if(is_array($message['recipients']) && count($message['recipients']) > 1) {
    // We only allow last recipient to be pass to the original workflow. For all other messages we send them through a new recursive function call
    $message_recursive = $message;
    $message['recipients'] = array(array_pop($message_recursive['recipients']));
    _privatemsg_send($message_recursive);
  }
}

If there is any other way to do this please reply.

suhas448’s picture

this function will returns the number of user.
_privatemsg_generate_user_array($thread['participants'], -1);

(Note: -1 will return last number of user )

find this function in module..
function phptemplate_privatemsg_list_field__participants($thread) {
//$participants = _privatemsg_generate_user_array($thread['participants'], -1);
drupal_set_message('

'.print_r($thread,1).'

');
$field = array();
$field['data'] = theme('username', $message['author']); //_privatemsg_format_participants($participants, 3, TRUE);
$field['class'] = 'privatemsg-list-participants';
return $field;
}

crawley’s picture

The ugliest and most crude way but it gets the job done :-) do it at your own risk in privatemsg.theme.inc

function theme_privatemsg_list_field__participants($variables) {
$thread = $variables['thread'];
$participants = _privatemsg_generate_user_array($thread['participants'], -4);
$field = array();
$field['data'] = _privatemsg_format_participants($participants, 3, TRUE);
$field['class'][] = 'privatemsg-list-participants';
return '';
}