User mention full name search is not working for Unicode names

I wont’t be too certain about saying never when it comes to software features. Software is to help people, not to punish them. There are good examples out there to learn from, how to implement something that caters to the needs of a broader audience. I understand that sometimes architectural design decisions, that were made earlier, may limit the ability to do specific things in specific ways, but user needs and good experience should always be the priority.

I am not well aware of the codebase, but here is one approach that could work efficiently while allowing full name searches with spaces in many languages. I am supposing here that the server looks up for matches in the user ID and full name fields for the mention queries. Here is a pseudo-code to illustrate how the client could behave (expressed in Ruby-ish syntax, though it would be JavaScript eventually, if implemented):

MAX_SUGGESTIONS = 6

result_cache = [] # use a set for deduplication, do not clear often to maximize reuse
prefix_match_exhausted = false # whether server returns less results than MAX_SUGGESTIONS
mention_mode = false
query_prefix = ""

def reset_mention
  prefix_match_exhausted = false
  mention_mode = false
  query_prefix = ""
end

def request_server
  results = response_from_server(query_prefix)
  result_cache.add(results)
  if results.length < MAX_SUGGESTIONS
    prefix_match_exhausted = true
  end
end

def populate_suggestions
  # cancel previous trigger if the timer is not up yet
  suggestions = find_in_cache(query_prefix)
  unless prefix_match_exhausted || suggestions.length >= MAX_SUGGESTIONS
    suggestions = request_server
    if suggestions.length.zero?
      reset_mention
    else
      render_auto_suggest(suggestions)
    end
  end
end

case typed_char
when "@"
  mention_mode = true
when "\r", "\n" # or any character that is neither allowed user IDs nor in full names
  reset_mention
when "\b"
  at_pos = position_of_at_sign_in_the_current_line
  if at_pos >= 0
    prefix_match_exhausted = false
    mention_mode = true
    query_prefix = current_line[at_pos..cursor_pos]
    populate_suggestions
  else
    reset_mention
  end
else
  if mention_mode
    query_prefix += typed_char
    populate_suggestions
  end
end

This is a rough illustration. There are other places that might improve the performance and reduce server queries, such as:

  • asking server to return more results for each query than required to populate the suggestions, this way successive queries can be avoided by spatial locality in the cache
  • there could be a min and/or max number of characters to trigger the mention_mode
  • the result_cache can use the trie data structure, with some flags on nodes that represent prefixes that were actually queried from the server to allow prefix_match_exhausted state
  • server may return results prioritized based on recent activity and/or reputation