add autocompleted names to private chats

Fix #1459

https://github.com/thelounge/lounge/issues/1459

Add rawNicks() to more easily get the list of nicks for the current
channel or chat without overly complicating its caller.
This commit is contained in:
Ed Brannin 2017-10-28 23:03:27 -04:00 committed by Pavel Djundik
parent 14ef881d17
commit 4e67e55a7d

View File

@ -261,23 +261,37 @@ function fuzzyGrep(term, array) {
return results.map((el) => [el.string, el.original]); return results.map((el) => [el.string, el.original]);
} }
function completeNicks(word, isFuzzy) { function rawNicks() {
const users = chat.find(".active .users"); const chan = chat.find(".active");
word = word.toLowerCase(); const users = chan.find(".users");
// Lobbies and private chats do not have an user list // If this channel has a list of nicks, just return it
if (!users.length) { if (users.length > 0) {
return []; return users.data("nicks");
} }
const words = users.data("nicks"); const me = $("#nick-value").text();
const otherUser = chan.attr("aria-label");
// If this is a query, add their name to autocomplete
if (me !== otherUser && chan.data("type") === "query") {
return [otherUser, me];
}
// Return our own name by default for anything that isn't a channel or query
return [me];
}
function completeNicks(word, isFuzzy) {
const users = rawNicks();
word = word.toLowerCase();
if (isFuzzy) { if (isFuzzy) {
return fuzzyGrep(word, words); return fuzzyGrep(word, users);
} }
return $.grep( return $.grep(
words, users,
(w) => !w.toLowerCase().indexOf(word) (w) => !w.toLowerCase().indexOf(word)
); );
} }