3 var Promise = require('bluebird');
4 var userService = require('gitter-web-users');
5 var inputsForUser = require('./elastic-inputs-for-user');
8 query: function(text, room) {
9 // not matching anything with an empty query, just like elastic
10 if (!text) return Promise.resolve([]);
12 var lcText = text.toLowerCase();
13 var userIds = room.oneToOneUsers.map(function(obj) {
17 return userService.findByIds(userIds).then(function(users) {
18 return users.filter(function(user) {
19 return getNames(user).some(function(name) {
20 return name.indexOf(lcText) === 0;
27 function getNames(user) {
28 // elastic normally does this analysis, but we're faking it
29 var nonWhitespaceAlternatives = [];
30 return inputsForUser(user)
31 .map(function(input) {
32 var lcInput = input.toLowerCase();
33 var nonWhitespace = lcInput
37 if (lcInput !== nonWhitespace) {
38 nonWhitespaceAlternatives.push(nonWhitespace);
42 .concat(nonWhitespaceAlternatives);