Closed (fixed)
Project:
Privatemsg
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
20 Jan 2011 at 19:38 UTC
Updated:
1 Aug 2011 at 07:45 UTC
Jump to comment: Most recent file
privatemsg_new() has tons of code that is either specific to new messages or replies.
This patch creates a new function, privatemsg_form_reply() that is used for replies instead. Shared parts are moved to common helper functions.
Although there are probably a few lines of code more, both the new and reply form function is now *much* easier to read and follow.
Actual changes for other modules:
- modules that want to change the reply form need to implement hook_form_privatemsg_form_reply_form_alter() now.
- The block hook is called for all recipients at the same time and only once. Allows to block all recipients based on certain conditions and is a performance improvement.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | new_reply_refactor2.patch | 20.46 KB | berdir |
| new_reply_refactor.patch | 19.52 KB | berdir |
Comments
Comment #2
berdirThis should fix the test fails.
Comment #3
te-brian commentedI wouldn't call it exhaustive testing, but I've been using this patch all day and sent many replies to threads with all types of recipients. Also created a number of new messages including message to entire roles that defers to the batch processing.
I also like that I can actually grok the new message form :)
[Edit], I also temporarily started using the block messages hook to shutdown all replies for a thread, but decided to do it differently because of redundant error messages being printed.
Comment #4
berdirCan you provide a screenshot of the printed errors?
We added that recently to avoid the "Why can't I respond" WTF moment when someone's inbox is full for example.
But we can likely improve it, at least visually and maybe even give modules implementing the blocked hook an option if the message should be shown or now.
Comment #5
berdirOk, thanks for testing, I decided to just go ahead and commit this since you and I tested it, all tests pass (and we have a *ton* of tests on these forms) and it would be hell to re-roll this patch if something in the form changes :)
Feel free to open an issue about the stuff in #4 or ping me in IRC.
Comment #6
andypostMaybe better privatemsg_reply_form() then current?
_new()
_reply_form()
Changing this in D7 we can backport this patch back to 6 and dont forget about changing docs about
Powered by Dreditor.
Comment #7
te-brian commentedre #4: The reason for the redundant messages is that the current code 'requires' a message for each blocked recipient. And then prints them all.
This would be for another issues, but perhaps we could think about how to hide or collapse messages, or at least provide a mechanism to do so. The 'disable replies' use case is a little special though, because it is unilaterally saying all recipients are blocked, and not for any good reason. The normal use cases (limits, bad behavior, etc.) would most likely follow the current per-recipient pattern.
Comment #8
te-brian commentedNote: Previously the new form accepted an array of recipients or a single recipient object. Obviously, since the tests passed, privatemsg did not take advantage of this fact. My custom module was overriding the new message menu router with a custom menu loader function that turned non-user arguments into an array of recipient objects. (this was necessary because the old logic assumed the string arg was a user).
Due to recent commits, I no longer need to do what I was doing. I can happily pass user_# or group_# etc. and things appear to be working.
So ... This is technically an API change (that may affect custom implementations), but now that we have proper string parsing of 'user_#' its is probably not neccesary to be able to pass an array or object anymore.
If we do want to retain the old functionality we just need to revert the changed lines above.
As a side note: I've never understood (and in my fork I have overridden) why we would not want the to_plain to be unique?
Powered by Dreditor.
Comment #9
berdirBecause unique is ugly :)
It looks weird enough in the input field but really ugly in the title.
See also #1017500: Only add the unique identifier for users added through the URL if necessary. That issue is about finding a way to only use the unique identifer when necessary. And in 99% of the cases, especially on sites which don't use realname.module, it's not.
Re: the single recipient object. Yes, I actually wanted to remove that, because we never used it anyway, I think I only added it initially so that the function is as flexible as possible but we never used it. (Well, you did... ;))
Comment #10
te-brian commentedI need the recipients to always be unique in the to field, because my magical auto-complete super-widget requires it :) (for matching keys to the human readable version).
One way I could deal with this without having to maintain it as a custom patch is if we move all the recipient parsing to a process function on $form['recipient']. Then I can just override that.
[Edit] The one downside is that modules that just want to form_alter will not have access to the true default_value, because that wouldn't be filled in until the process function runs.
Thoughts?
Comment #11
te-brian commentedWhatever we decide, we can probably move the last few comments to a new issue, so this discussion doesn't pollute the D7 porting.
Comment #12
berdirCommited to 7.x-2.x