User ID completion.
User ID completion.Completes A partially specified user ID, offering a menu of similar user IDs if the given ID was ambiguous. This function has two side effects:
- It renders user IDs in their canonical form, and
- It attaches the final user IDs shared segment if the user is online.
Partial user IDs of less than three characters will not even be considered. Most systems have huge numbers of users with the same first couple of letters.
If the partial user ID is found to be online, it is canonicalised and the function returns immediately. The user's shared segment is also attached.
Otherwise, the user ID is completed by building a list of all user IDs starting with the supplied user ID. If the list has only one member, the function returns it (and attaches the user's shared segment, if online).
If more than one user IDs match the partial, provided ID, the user is presented with a menu of the matching user IDs. At this point, the user can either select one of those user IDs by number, or enter an altogether new (possibly partial) user ID and the function will begin all over again. At any rate, if the user selects a user ID, the name is returned and the other user's shared segment is attached, if that user is online. Complicated, eh?
Oh, by the way, this function ends command concatenation if it is forced to present a menu. This makes sense, because the user wasn't expecting this, and it's probably best to not make any potentially dangerous assumptions about the operation being performed.
This completion function should be used wherever the system asks for (or expects) a user ID. The get_userid() high-level input function uses it. Even normally non-interactive parts of the system use it, like the page global command (/p). I thoroughly recommend duplicating this behaviour for any other strings that can be numerous, long and/or complicated.