Skip to content

Commit

Permalink
people auto complete: Also send user ID for users having same full name.
Browse files Browse the repository at this point in the history
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.

Uses `binarySearch` for better efficiency.
  • Loading branch information
agrawal-d committed May 8, 2020
1 parent a074337 commit 9da8b4b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/autocomplete/PeopleAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { Popup } from '../common';
import UserItem from '../users/UserItem';
import UserGroupItem from '../user-groups/UserGroupItem';
import binarySearch from '../utils/binarySearch';

type Props = $ReadOnly<{|
dispatch: Dispatch,
Expand All @@ -32,6 +33,17 @@ class PeopleAutocomplete extends PureComponent<Props> {
const { users, onAutocomplete } = this.props;
const user = users.find(x => x.email === email);
if (user) {
const idx = binarySearch(users, elem => {
if (elem.full_name === user.full_name && elem.user_id === user.user_id) {
return 1;
}
return elem.full_name.toLowerCase().localeCompare(user.full_name.toLowerCase());
});

if (idx !== undefined) {
onAutocomplete(`**${user.full_name}|${user.user_id}**`);
return;
}
onAutocomplete(`**${user.full_name}**`);
}
};
Expand Down

0 comments on commit 9da8b4b

Please sign in to comment.