Smf2.1: mention bug

Created on 29 Dec 2018  ·  17Comments  ·  Source: SimpleMachines/SMF2.1

member names problem with the same name

sample;

member A : kelvin

member B : kelvin klen

see other person (@ kelvin klen) mention notifications on their panel "@ kelvin"


@Antes hocam aynı isimle başlayan kullanıcı adları bahsetme bildirimlerinde sorun yaratıyor

örnegin "mehmet" isimli kullanıcı bir konuda "mehmet ali" isimli kullanıcıdan bahsedildiğinde kendi uyarı paneline sizden bahsedildi uyarısını görüyor halbuki bahsedilen "@ mehmet ali"

Steps to reproduce



    1. 2.

Environment (complete as necessary)

  • Version/Git revision:
  • Database Type:
  • Database Version:
  • PHP Version:

Additional information/references

Mentions

Most helpful comment

Please stick to english.

All 17 comments

Mrb test etmedim ama guzel yakalamissiniz

Confirmed. Maybe @Arantor can help with this?

Please stick to english.

Nothing to do with me, that was all Dragooon’s work, and it should be trying to match the longest match first. I half suspect it’s been “optimised” in the interim, though.

I'm thinking this might be the issue...

https://github.com/SimpleMachines/SMF2.1/blob/98d5cfd420ee2db29b1fd793751cc06e5ba4eb05/Sources/Mentions.php#L196-L200

Right before this, we replace   with a standard ASCII space, which of course is stripped by trim().

Theoretically we can fix this by changing the way the JS for mentions works. Since we already load up a list of names when you type @ followed by some characters, why not just insert the appropriate [mention={id}]@name[/mention] bbcode instead of just the @name? I haven't looked at the code for that but I would think we could pull the user IDs when we pull the names as well.

That sounds like an excellent solution, @Oldiesmann. Would you be willing to put together a PR for that?

I'll have to look into the JS further but will see what I can do :smiley:

Looking at this further I'm not entirely sure how we'd insert the bbcode instead of the name...

The ID is indeed loaded (and returned in the XML) for the members search. This is all handled through Themes/default/scripts/mentions.js, which returns the results to the atwho() function defined in jquery.atwho.min.js.

In the atwho file we have this (after unminfying it):

        displayTpl: "<li>${name}</li>",
        insertTpl: "${atwho-at}${name}",

This inserts the <li>{name}</li> in the background while displaying @{name} to the user. I guess the code in Mentions.php is what goes through the message and looks for mentions.

The actual bbcode in this case is "member" not "mention", but the same principle applies - we could do [member={id}]@name[/member].

Doesn’t that then force everyone who uses mentions to select from the autocomplete? I almost never click on autocomplete because usually I will have typed it out just fine.

The mod for 2.0 works the same way, and you don't need to use the autocomplete. It converts everything into a mention bbc after sending I think. Maybe look how that is done?

The mod is basically exactly the same, but the proposed solution here sounds like it would force users to use the bbcode which is unfriendly to use.

For some reason I was thinking the autosuggest was the only way to do it, which obviously isn't the case.

Taking a deeper look at things, I think I've finally managed to track down the problem:

In createPost(), we do this to replace @name with the appropriate bbcode:
https://github.com/SimpleMachines/SMF2.1/blob/ddab355b6a61686460e2bb65d2a36cc6b0b0494a/Sources/Subs-Post.php#L1729-L1734

The first line of code grabs an array of information about each member who was possibly mentioned, sorted according to the length of the name, in descending order. The problem is that we're not verifying that every "possibly mentioned member" is _actually_ mentioned after we do the str_irplace in getBody:

https://github.com/SimpleMachines/SMF2.1/blob/ddab355b6a61686460e2bb65d2a36cc6b0b0494a/Sources/Mentions.php#L104-L110

The solution here is simple. After we have the body with appropriate bbcode, we simply do something like this:

foreach($msgOptions['mentioned_members'] as $k => $m)
{
    if (preg_match('{pattern}', $body) === 0)
        unset($msgOptions['mentioned_members'][$k];
}

The "pattern" would match [member={int}]{$m['real_name']}[/member] (though I'm not good with regex so I don't know the exact pattern syntax for this).

Assuming $m contains what I think it does, this regex pattern should do it:

preg_match('~\[member=' . $m['id'] . '\]' . $m['real_name'] . '\[/member\]~u'`, $body)

If we need to match the @ symbol in the text, just stick it in.

I think a major problem

Milestone should be RC1 or RC2

@Oldiesmann - were you going to submit this PR?

PR #5337

Hello,

Problem persists in rc3 version

Sample;

""@ Mehmet"" sees ""@ Mehmet salim güllüce"" notifications in the alert panel

Was this page helpful?
0 / 5 - 0 ratings