I want to replace the participants list in the default module to sender. So I searched for it and found did the following as suggested at http://drupal.org/node/702934-
I went to the privatemsg.api.php folder of the module 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 after doing all this, I am still getting all the participants of the message in the mail. How do i overcome this?
Thanks in advance~~!!
shklnrj.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | preplacer.zip | 809 bytes | shklnrj |
Comments
Comment #1
berdirThere is no privatemsg.api.php folder, you need to create or extend an existing module use "modulename" instead of "hook".
See:
http://api.drupal.org/api/group/hooks/6
http://drupal.org/node/231276
http://geeksandgod.com/tutorials/computers/cms/drupal/creating-simple-dr...
Setting this to fixed since these are generic drupal questions, check the forums or IRC if you need help with creating modules/hooks.
Also note that this will just change the view at messages/view/thread_id, not the message list, that can currently not be easily changed.
Comment #2
berdirComment #3
shklnrj commentedI followed the methodology after reading the articles in the above links and made a module which is attached. I still can see all the participants in a message instead of the author.
Comments ??
Comment #4
berdirThe attached module does what it's supposed to do.
It does remove the other recipients when *viewing a thread* at messages/view/threadid. It does not change the list at messages. That is possible too, but needs a different hook.
Comment #5
berdirComment #6
YK85 commentedHi shklnrj,
I was wondering if u had any further progress with the custom module?
If so, would you kindly share it with the community?
Thanks!
Comment #7
andrew.lansdowne commentedIf you want to display sender only rather than all participants in the list view, simply paste this function into your theme's template.php (works with privatemsg version 6.x-1.1) - Don't forget to change the THEMENAME to your theme name:
It just removes the current user from the list of participants. Then you can also rename the column with this one:
Hope that helps.
EDIT: Changed the column name from "From" to "From / To" because privatemsg shows outgoing messages in the same table as incoming, and it is confusing to see message you've just sent appearing as if they were sent From your buddy.
Andy
Comment #8
berdirEdit: Misread the above, it just removes the current users, that should work correctly.
Comment #9
berdirIt seems that this has either been resolved in the mean time or there was no response in a long time, closing this issue.
Comment #11
drupalina commentedthe code in #7 worked for me. Thank you andrew.lansdowne!!!
Now, how can I replace the username of the participant to display an avatar with his/her username as an alt???
Comment #12
drupalina commentedI almost got it. Just need a little push.
I used
return theme('user_picture', $participant);instead ofreturn $field;in code given in #7 , but that returns the picture of the original author of the tread, rather than the picture of the last responder.How can I make it to return the picture of the last responder?
Comment #13
berdirThat is not easily possible because the list is not really sorted ( and right now, unfortunately, can't be sorted).
Maybe something like the following could work, but this is untested.
Note that this is just hacked together and might or might not work. Also, it will execute multiple additional queries for every displayed thread.
PS: Please open new issues or at least re-open the issue so that it is displayed in the list or I might not see your questions.
Comment #14
drupalina commentedI'm gonna reopen this issue because it relates to the original topic.
@ Berdir thanks a lot for your code! It works, but only half way. It displays the last responder's picture, but it does so even if the last responder is ME. If the last responder is me if ($uid == $user->uid), then to ME it should display the picture of the original author of the thread, the same logic as on Facebook's messages. So, I think we need another 1 line.
It would also be nice to see the usernames next to the avatars too. Basically I'm trying to replicate the exact Facebook message listings look and structure.
Comment #15
berdirI guessed as much, the problem here is the special case "message with only a single author - the current user". Because without that special case, what you are asking for is as simply as adding a condition like this:
If there is now a thread with a single message sent by the current user, this will simply display nothing. If that works for you, then fine...
To display the username beneath the picture, you can extend the "return .... " line as following:
This will show both the profile picture and the username, you will probably need some CSS to have them show up in the way you want.
Please set to active again if you have more questions or fixed if it works.
Also, you are welcome to create a new documentation page in the handbook (http://drupal.org/handbook/modules/privatemsg) explaining what you have done and how. Thanks!
Comment #16
berdirThere was no feedback so I assume that it did work. Marking this issue as fixed.
Comment #17
YK85 commentedHi,
I'm using 6.x-2.x and have it so users send messages to only one recipient at a time.
I want to change Participants to show the other user (ie remove the current user).
Would the below code work for 6.x-2.x in template.php or should I be doing this in a custom module?
Comment #18
berdirThat should work I think. If it doesn't, give me an actual error/problem :)
Comment #20
mpompili commentedI've divided Inbox from sent messages with the configuration option on: /admin/settings/messages
Choose the default list option: Inbox (x)
I guess you have to have privatemsg filter installed.
Then i check the url with this php snippet:
So i can put receiver or sender in the inbox page and in the sent messages page.
Comment #21
j0e commentedMarco thanks so much for #20, works really well at dividing things properly. Much appreciated.
Joseph
Comment #22
mpompili commentedHi Joseph. Glad to know that my code helped you out. :)
I've found out that if there's a checkbox on the left (needed to select a thread), the weight should be set to -49, so the checkbox is still on the first column on the left. Also this is a slightly shorter version.
Comment #23
mikestar5 commented#17
Very good solution!
Thanks