When I try to write a message to a user, sending form is opening and in the field "To" automatically appears the name of the user and "[user]". How I can correct it?

Files: 
CommentFileSizeAuthor
#30 privatemsg-recipient_unique_name-1852746-30.patch5.45 KBbogeyman
PASSED: [[SimpleTest]]: [MySQL] 3,176 pass(es).
[ View ]
#28 privatemsg-recipient_unique_name-1852746-28.patch5.16 KBbogeyman
FAILED: [[SimpleTest]]: [MySQL] 3,157 pass(es), 13 fail(s), and 6 exception(s).
[ View ]
#26 privatemsg-recipient_unique_name-1852746-26.patch5.16 KBbogeyman
FAILED: [[SimpleTest]]: [MySQL] 3,157 pass(es), 13 fail(s), and 6 exception(s).
[ View ]
#24 Screen Shot 2013-01-27 at 6.08.19 PM.png31.06 KBtjhart87
#18 privatemsg-recipient_unique_name-1852746-18.patch5.36 KBbogeyman
PASSED: [[SimpleTest]]: [MySQL] 4,878 pass(es).
[ View ]
#16 privatemsg-recipient_unique_name-1852746-15.patch3.71 KBbogeyman
PASSED: [[SimpleTest]]: [MySQL] 4,859 pass(es).
[ View ]
#15 privatemsg-recipient_unique_name-1852746-15.patch3.71 KBbogeyman
PASSED: [[SimpleTest]]: [MySQL] 4,859 pass(es).
[ View ]
#13 privatemsg-recipient_unique_name-1852746-13.patch4.27 KBbogeyman
FAILED: [[SimpleTest]]: [MySQL] 4,858 pass(es), 3 fail(s), and 0 exception(s).
[ View ]
#9 privatemsg-recipient_unique_name-1852746-9-do-not-test.patch1.91 KBbogeyman
#7 privatemsg-recipient_name-1852746-7.patch1.8 KBbogeyman
FAILED: [[SimpleTest]]: [MySQL] 4,852 pass(es), 7 fail(s), and 0 exception(s).
[ View ]
err.png104 KBfuntik44

Comments

SimonLitt’s picture

I have a similar error on 7.x-1.3 version, but the "To" field contains the following text:

User1 [user: User1]
SimonLitt’s picture

When module "Privatemsg Realname Integration" is disabled I get "User1 [user]" at the field.

SimonLitt’s picture

This text add theme_privatemsg_username function at privatemsg.theme.inc:

<?php
if (!empty($options['plain'])) {
   
$name = check_plain(format_username($recipient));
    if (!empty(
$options['unique'])) {
     
$name .= '[user]';
    }
    return
$name;
  }
?>

The options unique it gets from privatemsg_new function at privatemsg.pages.inc

<?php
$to_plain
[privatemsg_recipient_key($recipient)] = privatemsg_recipient_format($recipient, array('plain' => TRUE, 'unique' => $unique));
?>
bogeyman’s picture

Status:Active» Needs review

It's a bit weird for me. When I comment this line in the privatemsg.theme.inc :

<?php
if (!empty($options['unique'])) {
 
$name .= '[user]';
}
?>

The message is still sent normally.

I think the author has his own intention for that.

Berdir’s picture

Status:Needs review» Needs work

This is not a technical bug (you'll notice that you can send the message just fine) but a usability one. A big one, because there's a new issue for this every two weeks ;)

Privatemsg supports different recipient types and we currently do not know if there is another one with the same name (for example a role, or if you are using realname integration). If we would leave it out, then there would be a validation error afterwards.

What needs to be done is generate the name without unique, check all other types if they can resolve that and only use unique if that is the case.

Closing the following issues as duplicates:
- #1254212: How can I remove [user] string?
- #1749106: "[user]" is added to username when clicking "Send author a message"
- #1392820: Remove [role] when composing message from profile

tjhart87’s picture

I'm assuming you are referring to [user: 'whatever'] as unique? I'm still not sure I follow how to remove that from the string.

bogeyman’s picture

Status:Needs work» Needs review
StatusFileSize
new1.8 KB
FAILED: [[SimpleTest]]: [MySQL] 4,852 pass(es), 7 fail(s), and 0 exception(s).
[ View ]

I created this patch to check if the recipient name is also used by the other recipient type. Only if it used by the other type such as role, then we will use unique option.

Status:Needs review» Needs work

The last submitted patch, privatemsg-recipient_name-1852746-7.patch, failed testing.

bogeyman’s picture

Status:Needs work» Needs review
StatusFileSize
new1.91 KB

This is the update for my previous patch. I increase the limit number to anticipate if there are some almost similar recipients name. I know that this patch won't pass the automated test because the test script is checking that the recipient field should contain [user].

Berdir’s picture

Any reason for not just using http://api.worldempire.ch/api/privatemsg/privatemsg.module/function/_pri... to check for identical other recipients? You can pass in the username and check the returned value. There should be exactly one recipient and no duplicate errors returned.

You can obviously adjust the tests to account for the actual situation now (= remove the [user]). However, you should also make sure that your code works by adding a few more more checks with a user that has the same name as a role.

bogeyman’s picture

Oww, I just didn't know there is such function. Thanks for the information, it makes the code simpler in checking the recipient name. Yes, I have tested with the case when user's name and role's name are the same. If that's the case the [user] will appear after the recipient name.

Berdir’s picture

I'm sure you have tested it :)

What I meant is writing automated test, so that we can be sure that future changes will not break this. Unless you want to volunteer to re-do your tests for every single patch that will ever be commited ;)

bogeyman’s picture

StatusFileSize
new4.27 KB
FAILED: [[SimpleTest]]: [MySQL] 4,858 pass(es), 3 fail(s), and 0 exception(s).
[ View ]

I have updated the test script to create a role with the same name like the one of the username. But, the result in the test script is different from the one I test in the real site. In the real site, I get [user] if the username is the same like the role name, but in the test script the [user] is not appear even though I have created a role with the same name like the one of the username. I also have enabled the Privatemsg Role module in the test script.
Any suggestion for this?

Status:Needs review» Needs work

The last submitted patch, privatemsg-recipient_unique_name-1852746-13.patch, failed testing.

bogeyman’s picture

StatusFileSize
new3.71 KB
PASSED: [[SimpleTest]]: [MySQL] 4,859 pass(es).
[ View ]

If I just remove the [user], the script will pass the automated test although there is a role with the same name as the username.

bogeyman’s picture

Status:Needs work» Needs review
StatusFileSize
new3.71 KB
PASSED: [[SimpleTest]]: [MySQL] 4,859 pass(es).
[ View ]

If I just remove the [user], the script will pass the automated test although there is a role with the same name as the username.

Berdir’s picture

Sorry for taking so long to respond.

The reason for that are permissions. The user is not allowed to write to a role, so that function filters it out. It works locally when I give the author the 'write privatemsg to all roles' permission. Permissions are often a reason if things work differently in a test than manually, especially when testing with uid 1 :)

What would be perfect would be a test for both a user with permissions and one without.

Start with the patch in #6, add another user (e.g. $role_author) with the additional role permission and then check that in that case, it does display role.

bogeyman’s picture

StatusFileSize
new5.36 KB
PASSED: [[SimpleTest]]: [MySQL] 4,878 pass(es).
[ View ]

Nice.. Why didn't I realize it before that the problem is the permission. Here is the new patch.

Berdir’s picture

Version:7.x-2.x-dev» 7.x-1.x-dev
Status:Needs review» Patch (to be ported)

Looks good. Commited to 7.x-2.x and 6.x-2.x, is this necessary for 7.x-1.x as well? Patch didn't apply. If not, feel free to set to fixed.

tjhart87’s picture

I was having this problem with the 7.1 release. Is there a way to commit this there as well?

tjhart87’s picture

I was having this problem with the 7.1 release. Is there a way to commit this there as well?

-Mania-’s picture

The issue was started for 7.x-1.x so it's strange it's applied everywhere else except there.

Berdir’s picture

No,it's not strange. 7.x-2.x is where active development happens and bugfixes are then backported but that requires manual work. You're welcome to update the patch.

tjhart87’s picture

StatusFileSize
new31.06 KB

I updated to the dev version and am still having my TO field populated with [user: username]. Is there not a way to remove that from the field? See screenshot.

bogeyman’s picture

When the Realname Integration module is not enabled, the patch will work. But it will be different if you used enable Realname Integration. I think the problem should be discussed in the new issue that is also related to your problem. Here is the link.
http://drupal.org/node/1903786

bogeyman’s picture

Status:Patch (to be ported)» Needs review
StatusFileSize
new5.16 KB
FAILED: [[SimpleTest]]: [MySQL] 3,157 pass(es), 13 fail(s), and 6 exception(s).
[ View ]

While the 7.x-2.x branch hasn't had the stable release yet, I created the patch for 7.x-1.x branch.

Status:Needs review» Needs work

The last submitted patch, privatemsg-recipient_unique_name-1852746-26.patch, failed testing.

bogeyman’s picture

Status:Needs work» Needs review
StatusFileSize
new5.16 KB
FAILED: [[SimpleTest]]: [MySQL] 3,157 pass(es), 13 fail(s), and 6 exception(s).
[ View ]

Re-submit the patch for #26

Status:Needs review» Needs work

The last submitted patch, privatemsg-recipient_unique_name-1852746-28.patch, failed testing.

bogeyman’s picture

Status:Needs work» Needs review
StatusFileSize
new5.45 KB
PASSED: [[SimpleTest]]: [MySQL] 3,176 pass(es).
[ View ]

Sorry, I forgot to enable the "privatemsg_roles" module in the test script... Re-submit the patch for the 7.x-1.x branch.

jshamley’s picture

patch worked for me. private_message 7.x-1.4 thanks!

jshamley’s picture

dberror’s picture

Issue summary:View changes

#30 worked for me too.

ptmkenny’s picture

Status:Needs review» Reviewed & tested by the community

In response to Berdir's request in #19 (Do we need this for 1.x?), the answer appears to be yes, and the patch for 1.x in #30 is RTBC.

afranioce’s picture

#30 worked for me too.

tr33m4n’s picture

Status:Reviewed & tested by the community» Needs work

Hello there, although #30 did work it seems that if more than one person has the same RealName on the site a warning comes up about selecting the right recipient. In the system I'm building users aren't meant to know the email address of the person they are messaging therefore cannot accurately select the right recipient for the message. Is there a way around this? Maybe some way of simply hiding the values rather than removing them from the string?

Cheers
Dan

ptmkenny’s picture

@tr33m4n My site uses the UID instead of the e-mail address to keep users unique for real name; that way, I am able to sidestep this issue. You may be able to do so in the same way.

tr33m4n’s picture

Status:Needs work» Reviewed & tested by the community

Ah, fair enough, for some reason I forgot about those settings! I'll give that a go and see where it gets me :) Thanks

tr33m4n’s picture

Status:Reviewed & tested by the community» Needs work

That did not work, the message "The site has multiple recipients named Joe Bloggs. Please choose your intended recipient:" still shows up asking you to choose a recipient, only this time it's slightly more confusing to the end user as there's the UID appending to each name rather than email.

tr33m4n’s picture

It's almost as if it breaks RealName functionality a little bit... Imagine a huge site with a huge user base, I'd guarantee everyone would see this error and have to guess which was the real "Joe Bloggs" from a UID/email! I am using the privatemsg "send message" field in a view, could it be something to do with that? Maybe it's not identifying the correct UID and falling back to RealName? I don't know

Cheers
Dan

arukado’s picture

Thx! #30 worked!