Some prominent or controversial users within a site might not want to receive private messages. They should beable to opt out via the user profile page.

I intend to begin coding this soon unless someone beats me to it.

CommentFileSizeAuthor
#2 privatemsg_0.patch4.96 KBmoshe weitzman

Comments

TDobes’s picture

Sounds like a good idea. Please keep private messages enabled by default, though.

moshe weitzman’s picture

StatusFileSize
new4.96 KB

As promised, here is the patch. If acceptable, please consider applying to 4.5 as well.

TDobes’s picture

Sorry for the delay in responding.

I have committed a modified version of this patch. Changes include:
* Hide the "view inbox" menu item when private messages are disabled.
* Changed the logic so private messages are enabled by default (also made mail alerts enabled by default; this should not affect current users).
* Removed the check of privatemsg_allow for in the _link hook. The $arg that is passed is a node object, not a user object. We'd have to use user_load to obtain the user object, which would add several db_queries on multi-node pages... I'm not sure it's worth it.
* Removed the logic in the _user hook that checked the value for $edit. Correct me if I'm wrong, but won't $edit only differ from $user if we've failed the validation step for some reason and been returned to the same form? I don't see any other modules that do a check like this, but maybe I'm just not looking closely enough. Feel free to dispute this.

Thanks for your work!

moshe weitzman’s picture

Thanks for the review. A few notes:

- I was allowing disabled users to vie their inbox in case they have old messages there, or wish to send a message (but they can't receive a reply). These are marginal cases, so it may makesense to disable as you've suggested
- the node object that is pased in _link hook has info about the author in it. Specifically, it has the user's picture, and everything in the data column. See node_load(). Since this pref is stored in the data column, its present in $node. I suggest accepting this part of the patch.
- that correct that edit differs when there has been a validation error. In the case of a validation error (which could be thrown by any module for unrelated data), we want avoid 'forgetting' the posted data. Thats why we use $edit if it exists. If not, we fall back on values from the DB (i,e the $user object). This is a common practice in Drupal, but not as common as it should be.

TDobes’s picture

- I was allowing disabled users to vie their inbox in case they have old messages there, or wish to send a message (but they can't receive a reply). These are marginal cases, so it may makesense to disable as you've suggested

I would like to avoid displaying the inbox menu item when users have turned off their ability to accept messages. Perhaps I could leave it accessable by changing the menu item type of MENU_CALLBACK for users who've disabled private messages?

- the node object that is pased in _link hook has info about the author in it. Specifically, it has the user's picture, and everything in the data column. See node_load(). Since this pref is stored in the data column, its present in $node. I suggest accepting this part of the patch.

You are correct; I should have checked node.module. For some reason, this code didn't work when I tested it, though... perhaps an error on my part. I'll give it another try and see if I can figure out what happened.

- that correct that edit differs when there has been a validation error. In the case of a validation error (which could be thrown by any module for unrelated data), we want avoid 'forgetting' the posted data. Thats why we use $edit if it exists. If not, we fall back on values from the DB (i,e the $user object). This is a common practice in Drupal, but not as common as it should be.

OK, agreed. I will commit this part of the patch later today. I suppose I should look through the other modules I use and see whether they do this.

TDobes’s picture

OK... I committed the changes I mentioned in the last comment. (to both the 4.5 and HEAD branch)

Thanks, Moshe!

Anonymous’s picture