mattermost / mattermost-plugin-msteams

Other
12 stars 10 forks source link

MM-58485: fix duplicate at-mentions #694

Closed lieut-data closed 3 weeks ago

lieut-data commented 1 month ago

Summary

Teams sometimes translates an at-mention for a user like Miguel De La Cruz into four discrete mentions. Fortunately, these are combined in a way that's unique relative to adjacent mentions, even for the same user, so we can detect and patch these deterministically.

There was code that attempted to handle this, but it seemed to only deal with two mentions in a row. For reference, the payload from Teams looks something like this:

"body": {
    "content": "<p>hello <at id=\"0\">Miguel</at>&nbsp;<at id=\"1\">de</at>&nbsp;<at id=\"2\">le</at>&nbsp;<at id=\"3\">Cruz</at></p>"
    },
    "attachments": [],
    "mentions": [{
        "id": 0,
        "mentionText": "Miguel",
        "mentioned": {
            "user": {
                "id": "...",
                "displayName": "Miguel",
            }
        }
    }, {
        "id": 1,
        "mentionText": "de",
        "mentioned": {
            "user": {
                "id": "...",
                "displayName": "de",
            }
        }
    }, {
        "id": 2,
        "mentionText": "la",
        "mentioned": {
            "user": {
                "id": "...",
                "displayName": "la",
            }
        }
    }, {
        "id": 3,
        "mentionText": "Cruz",
        "mentioned": {
            "user": {
                "id": "...",
                "displayName": "Cruz",
            }
        }
    }
...

And ended up looking something like this:

CleanShot 2024-06-06 at 17 16 55@2x

While we're in here, remove a redundant space after mentions.

Ticket Link

Fixes: https://mattermost.atlassian.net/browse/MM-58484