Skip to content

Commit 2bb5bae

Browse files
committed
boxes: Use user_ids in autocomplete for ambiguous user mentions.
Prior to this commit, user mentions through autocomplete used only names in the typeahead. This commit appends `user_id`s to all the multiple instances of the same name to use the **Name|User_id** format of user mentions. The appended user_id would serve as a distinction between users having the same name. Tests updated.
1 parent 306a394 commit 2bb5bae

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

zulipterminal/ui_tools/boxes.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,23 @@ def autocomplete_users(self, text: str, prefix_string: str
445445
reverse=True)
446446

447447
user_names = [user['full_name'] for user in sorted_matching_users]
448+
449+
user_name_duplicates = [user_name
450+
for count, user_name in enumerate(user_names)
451+
if user_name in user_names[:count]]
452+
453+
user_names_with_distinct_duplicates = [
454+
f"{user['full_name']}|{user['user_id']}"
455+
if user['full_name'] in user_name_duplicates
456+
else user['full_name']
457+
for user in sorted_matching_users
458+
]
459+
448460
extra_prefix = "{}{}".format(
449461
'*' if prefix_string[-1] != '*' else '',
450462
'*' if prefix_string[-2:] != '**' else '',
451463
)
452-
user_typeahead = format_string(user_names,
464+
user_typeahead = format_string(user_names_with_distinct_duplicates,
453465
prefix_string + extra_prefix + '{}**')
454466

455467
return user_typeahead, user_names

0 commit comments

Comments
 (0)