From ebcaae257cb5931eb1eb6714f2941e4257fef3ea Mon Sep 17 00:00:00 2001 From: Divyanshu Agrawal Date: Thu, 7 May 2020 16:21:47 +0530 Subject: [PATCH] people auto complete: Also send user ID for users having same full name. Previously, our @-mention autocomplete had a bug, wherein it failed to correctly mention the specific user if more than one users had the same full name. Now, if more than one users have the same full name, we send the user ID as well to ensure that the correct user is @-mentioned. The user ID is not sent for every @-mention to ensure the behaviour is consistent with the web app, i.e., we send it only in case of ambiguity. See the `get_mention_syntax` function in `static/js/people.js` in the webapp source for the origin of this syntax. --- src/autocomplete/PeopleAutocomplete.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/autocomplete/PeopleAutocomplete.js b/src/autocomplete/PeopleAutocomplete.js index 4e9f5a3d7c1..a8a0de625eb 100644 --- a/src/autocomplete/PeopleAutocomplete.js +++ b/src/autocomplete/PeopleAutocomplete.js @@ -32,6 +32,14 @@ class PeopleAutocomplete extends PureComponent { const { users, onAutocomplete } = this.props; const user = users.find(x => x.email === email); if (user) { + // If another user with the same full name is found, we send the + // user ID as well, to ensure the mentioned user is uniquely identified. + if (users.find(x => x.full_name === user.full_name && x.user_id !== user.user_id)) { + // See the `get_mention_syntax` function in + // `static/js/people.js` in the webapp. + onAutocomplete(`**${user.full_name}|${user.user_id}**`); + return; + } onAutocomplete(`**${user.full_name}**`); } };