Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
The above thing is not working.
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??
How about creating you module
How about creating you module called for example "your_module" and then
function your_module_privatemsg_sql_participants_alter(&$fragment, $thread_id) {
...
}
NOP Dont work
NOP Dont work
Did NOt Work
Hey i made my custom module and used the above code for finishing the task. But still it did not work out for me.
Don´t work. If you reply to a
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.
It might be useful if we also
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)
If there is any other way to do this please reply.
Drupaler China
_privatemsg_generate_user_array($thread['participants'], -1);
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('
');
$field = array();
$field['data'] = theme('username', $message['author']); //_privatemsg_format_participants($participants, 3, TRUE);
$field['class'] = 'privatemsg-list-participants';
return $field;
}
Crude but it works
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 '';
}