From 4e67e55a7dccb0f7359cc2a5fbdafc88e40966d5 Mon Sep 17 00:00:00 2001 From: Ed Brannin Date: Sat, 28 Oct 2017 23:03:27 -0400 Subject: [PATCH] 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. --- client/js/autocompletion.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/client/js/autocompletion.js b/client/js/autocompletion.js index ec8e1d7f..1b95d009 100644 --- a/client/js/autocompletion.js +++ b/client/js/autocompletion.js @@ -261,23 +261,37 @@ function fuzzyGrep(term, array) { return results.map((el) => [el.string, el.original]); } -function completeNicks(word, isFuzzy) { - const users = chat.find(".active .users"); - word = word.toLowerCase(); +function rawNicks() { + const chan = chat.find(".active"); + const users = chan.find(".users"); - // Lobbies and private chats do not have an user list - if (!users.length) { - return []; + // If this channel has a list of nicks, just return it + if (users.length > 0) { + 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) { - return fuzzyGrep(word, words); + return fuzzyGrep(word, users); } return $.grep( - words, + users, (w) => !w.toLowerCase().indexOf(word) ); }