First, thanks for this great module!
I have created 'trash' tab, using custom module:

function trash_privatemsg_menu() {
  $items['messages/trash'] = array(
    'title'            => 'Trash',
    'page callback'    => 'drupal_get_form',
    'page arguments'   => array('privatemsg_list', 'trash'),
    'access callback'  => 'privatemsg_user_access',
    'access arguments'  => array('read privatemsg'),
    'type'             => MENU_LOCAL_TASK,
    'weight'           => -10,
  );
  return $items;
}
function trash_privatemsg_privatemsg_sql_list_alter(&$fragments, $account, $argument) {
 if ($argument == 'trash') {
   $fragments['where'][1] = 'pmi.deleted > 0' ;
 }
}



Now, i have 2 questions:
1) how it is possible to restore message from Trash to Inbox? I saw module already have function privatemsg_message_change_delete for delete or restore a message, so probably i can use hook_form_alter to add 'Restore' button if we are in 'trash' section, and then hook_form_submit for restoring?

2) When message was deleted (just changed pm_index 'deleted' value) it is not possible to view content of message, when i go to /messages/view/1 i see 'Page not found' . Is it possible to show the content of deleted message without modifying core privatemsg module?

Thanks again and have a good day!

CommentFileSizeAuthor
#3 privatemsg_trash.zip2.92 KBbabruix
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir’s picture

Status: Active » Postponed (maintainer needs more info)

1) Yes, that should be possible. You might want to check out my patch at #660092: Use tag for inbox handling since that is very similiar and adds a "Archive" button only to the Inbox. The patch adds a new #list_argument to the $form definition, conditionally adds the archive button based on that and defines a submit function. For the submit function, you can copy the delete operation definiton from http://blog.worldempire.ch/api/function/privatemsg_privatemsg_thread_ope... and simply switch the callback/undo callback (arguments) definitions. Not that you can rely on arg() to determine if you are in the trash. So you don't need the patch but it's not as clean.

2) Basically, you should be able to to do the same for the messages query as you are doing for the list query now:
http://blog.worldempire.ch/api/function/hook_privatemsg_sql_messages_alt...
http://blog.worldempire.ch/api/function/privatemsg_sql_messages/1

The tricky part is to get something similiar to the list argument into the message view. You could do something like messages/view/1/deleted, but the query is generated in a theme function, so you need to override that theme function. I've done that already here : #727588-3: disable threaded view (You just need the theme_registry hook, and then use the default theme function and extend it with /deleted when necessary).

This should get you started.

I'm sure there will be other issues, for example, you might want to replace the "delete message" link with "restore message". You can and alter these links with the following hook: http://blog.worldempire.ch/api/function/hook_privatemsg_message_view_alt...

Oh, and it would be great if you could publish your module in the issue queue if get it working, others might be interested in it too. If you do, you should rename it to privatemsg_trash to avoid namespace clashes with other modules out there.

Set this to active if you have more questions or fixed if not.

YK85’s picture

+1 subscribing

babruix’s picture

Status: Postponed (maintainer needs more info) » Active
FileSize
2.92 KB

Thanks for your detailed reply!
For now i have finished with 1) restoring from trash, but have some problems with 2) view deleted message.
I`m attaching privatemsg_trash module and would be great if you can look and tell why menu messages/view/1/deleted not working at all.

Berdir’s picture

Status: Active » Postponed (maintainer needs more info)

Had no time try it yet, just a few things I noted in your code

- you don't need to create empty hooks (nor the empty .install file) if you don't need it
- You shouldn't need your own trash_view function nor the menu entry. Everything in there can be altered
- privatemsg_trash_privatemsg_sql_messages_alter() is empty, so it's obvious that it doesn't work :)
- privatemsg_trash_privatemsg_message_view_alter() You probably also want to remove the existing Delete link
- privatemsg_trash_privatemsg_thread_operations() You can of course do this, but note that this will only give you a option in the default select. If you want a button, you need to do it like I did in the linked issue
- function privatemsg_trash_thread_change_delete($threads, $delete, $account = NULL) { Why do you need that function?

Berdir’s picture

Version: 6.x-1.1 »
Category: support » feature
Status: Postponed (maintainer needs more info) » Needs work

Not sure if the issue starter is still working on it, but this is a feature request, so if anyone wants to pick this up, there are some hints in the post above...

Bilmar’s picture

subscribing - If there is further development in this new feature I would like to help with any testing needed. Sounds like a new feature the community would really benefit from. Thanks

YK85’s picture

I'm not sure how other email services work, but the below would be a great flow process:

1) when a message is deleted from the Inbox it gets tagged 'deleted' and moved to the Trash

2) messages with 'deleted' tag are removed permanently after x days (an admin setting) or can be permanently deleted manually from the server
Gmail Trash page: Empty Trash now (messages that have been in Trash more than 30 days will be automatically deleted)

3) messages with 'deleted' tag can be moved back into inbox, and 'deleted' tag removed

oadaeh’s picture

Version: » 6.x-2.x-dev
Issue summary: View changes
Status: Needs work » Closed (won't fix)

This issue is being closed because it is against a branch for a version of Drupal that is no longer supported.
If you feel that this issue is still valid, feel free to re-open and update it (and any possible patch) to work with the 7.x-1.x branch (bug fixes only) or the 7.x-2.x branch.
Thank you.