Imho (and litwol agreed on irc ;) ) our hook_form_alter is pretty ugly, it does heavily change our own form based on arg().

The attached patch tries to change that and changes the following things:

New privatemsg_new interface:

function privatemsg_new(&$form_state, $recipients = array(), $subject = '', $thread_id = NULL) {

This means:
- Multiple default recipients are possible. There is some pretty ugly code to detect what $recipient is, because it could be an array of user objects or a string like "uid1,uid2,uid3". I tried to make this nicer with using a named menu wildcard but that doesn't work because such a thing doesn't work together with an empty array. it has to return either FALSE or a actual value.
- It is possible to set a subject
- By setting a thread_id, the form "converts" to a reply form, with fixed subject and to field. Currently, the recipients field is displayed as a disabled textfield but that has the downside that not all names will be displayed when there the list is too long. I am not sure if I should change that to a description or so. (Note: the disabled field is _not_ used, it's just displayed.
- Changed the menu hook to allow urls like: /messages/new/1,4,5/Subject
- Changed privatemsg_get_link, it is now possible to provide a subject and an array of recipients. This is a possible fix for #382756: Allow to set subject and body with query arguments

This is nothing important, conflicts with several other patches and is only a first (working but ugly) version, but I'm submitting it to get some feedback...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir’s picture

FileSize
13.23 KB
11.23 KB

Ok, attached is a re-roll. Instead of a disabled textfield, it's now displayed as simple text, see screenshot. I think that's better for many users because you can't see all of them in a disabled input field.

NaheemSays’s picture

Status: Needs review » Needs work

when going to messages/new/%, the subject is being set to whatever % is, instead of leaving it blank.

Secondly, going to messages/new/%/subject_title shows a reply form instead of the normal new message form. Is that how its meant to be? if so, then good. if not, then, its still ok. Just not what I expected.

Also if we are dealing with this all, the following was a sort of hack that I added:

  if (empty($to) && $usercount >= 1) {
    // Assume the user sent message to own account as if the usercount is one or less, then the user sent a message but not to self.
    $to[] = $user->name;
  }

It has the nice side effect of allowing the person to reply to itself, but its not really as clever as it could be. We can leave it as is, or we can do something about it. up for ideas.

That current check should always be greater than or = 1 when a person has taken part in a conversation (simply by receiving the message). I guess we could even remove the && $usercount >= 1 bit?

(at the very least, should there be a comment to let people know that it is a hack?)

Berdir’s picture

Status: Needs work » Needs review
FileSize
11.82 KB

I can't reproduce that, are you sure you cleared the menu cache as privatemsg_menu() changed slightly?

Attached is a updated patch which fixes a few issues with multiple recipients. I also replaced your "hack" with a simple check to only add a a recipient once, it will currently display your name own name too.

That stuff is confusing anyway, because if you write UserA once, and then go to the thread, it will display "Reply to UserA", which isn't actually what you are doing.

Maybe something like:

Reply to thread
Recipients: UserA, UserB

Berdir’s picture

No idea why that didn't work, can you try again with that patch?

NaheemSays’s picture

I have re added that logic which I thought was a hack - with the new code it actually worked properly.

As for the display, I like your proposed format in comment 3 - not done here as I have no idea how to.

Apart from that the patch is ready.

NaheemSays’s picture

Status: Needs review » Needs work

This patch needs to be rerolled and may also need to take into account #349389-5: Page titles do not change.

litwol’s picture

Priority: Normal » Critical

Fixing this is top priority, it doesn't make much sence to form_alter own forms when we can just modify the form in code where needed.

Berdir’s picture

Status: Needs work » Needs review
FileSize
11.7 KB

Re-roll, this also fixes the issue with the title.

NaheemSays’s picture

Status: Needs review » Reviewed & tested by the community

This works well with one caveat, which was mentioned before.

Sending a message to yourself with the method messages/new/% works - as does replies to an existing thread.

However if the new message format is messages/new/%,% where one of the many comma separated uids is your own, that is not entered as a recipient, just all the other uids.

Afaik, that is acceptable as the message will still appear in your own messages and it does not impact on any other aspects of conversation building.

Setting to rtbc

(if anyone else tests this patch, remember top clear the cache beforehand - I have been caught out by that twice now.)

igorik’s picture

I think that it would be great it admin could set different numbers of allowed recipients for various roles, e.g. 10 for auth. user role, 100 for trusted user role, etc.

thanks
Igorik
http://www.somvprahe.sk

Berdir’s picture

That patch is not related to such an option, and you can always use hook_form_alter, no need to change privatemsg.module : http://api.drupal.org/api/function/hook_form_alter/6

However, it is a possible setting that could be added to the message quota module: #69856: Message limits

aharown07’s picture

Intend to try this patch out ... sounds like a really good move to me.

aharown07’s picture

I've applied this patch and it looks good so far. Thanks.

aharown07’s picture

Just updated to new dev release and had to apply the patch again. Could we get this patch rolled into the next dev?

litwol’s picture

Status: Reviewed & tested by the community » Fixed

/me does a happy tribal dance of victory.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.