From f7b7248ff7b0f606f409106bc09b4b086387a401 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Thu, 27 Apr 2017 21:32:58 +0300 Subject: [PATCH] Fix nick autocomplete Fixes #1119. --- client/js/lounge.js | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/client/js/lounge.js b/client/js/lounge.js index 2d9eac34..b11b2fc7 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -300,8 +300,9 @@ $(function() { var nicks = chan.find(".users").data("nicks"); if (nicks) { var find = nicks.indexOf(data.msg.from); - if (find !== -1 && typeof move === "function") { - move(nicks, find, 0); + if (find !== -1) { + nicks.splice(find, 1); + nicks.unshift(data.msg.from); } } } @@ -389,9 +390,9 @@ $(function() { .attr("placeholder", nicks.length + " " + (nicks.length === 1 ? "user" : "users")); users + .data("nicks", nicks) .find(".names-original") - .html(templates.user(data)) - .data("nicks", nicks); + .html(templates.user(data)); // Refresh user search if (search.val().length) { @@ -1380,7 +1381,13 @@ $(function() { } function completeNicks(word) { - const users = chat.find(".active").find(".names-original"); + const users = chat.find(".active .users"); + + // Lobbies and private chats do not have an user list + if (!users.length) { + return []; + } + const words = users.data("nicks"); return $.grep( @@ -1534,17 +1541,6 @@ $(function() { $("#nick-value").text(nick); } - function move(array, old_index, new_index) { - if (new_index >= array.length) { - var k = new_index - array.length; - while ((k--) + 1) { - this.push(undefined); - } - } - array.splice(new_index, 0, array.splice(old_index, 1)[0]); - return array; - } - function toggleNotificationMarkers(newState) { // Toggles the favicon to red when there are unread notifications if (favicon.data("toggled") !== newState) {