From 7af573fd967affd9bf4a6ed07451f34af67490e7 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Mon, 10 Jul 2017 13:56:37 +0300 Subject: [PATCH] Handle auto completion order on the server Fixes #289. --- client/js/render.js | 22 +++++----------------- src/models/chan.js | 6 +++++- src/models/user.js | 4 +++- src/plugins/irc-events/message.js | 6 ++++++ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/client/js/render.js b/client/js/render.js index 721dd603..2cebfdb6 100644 --- a/client/js/render.js +++ b/client/js/render.js @@ -81,7 +81,7 @@ function buildChatMessage(data) { renderPreview(preview, msg); }); - if ((type === "message" || type === "action") && chan.hasClass("channel")) { + if ((type === "message" || type === "action" || type === "notice") && chan.hasClass("channel")) { const nicks = chan.find(".users").data("nicks"); if (nicks) { const find = nicks.indexOf(data.msg.from); @@ -143,22 +143,10 @@ function renderChannelMessages(data) { function renderChannelUsers(data) { const users = chat.find("#chan-" + data.id).find(".users"); - let nicks = users.data("nicks") || []; - const oldSortOrder = {}; - - for (const i in nicks) { - oldSortOrder[nicks[i]] = i; - } - - nicks = []; - - for (const i in data.users) { - nicks.push(data.users[i].nick); - } - - nicks = nicks.sort(function(a, b) { - return (oldSortOrder[a] || Number.MAX_VALUE) - (oldSortOrder[b] || Number.MAX_VALUE); - }); + const nicks = data.users + .concat() + .sort((a, b) => b.lastMessage - a.lastMessage) + .map((a) => a.nick); const search = users .find(".search") diff --git a/src/models/chan.js b/src/models/chan.js index 66418195..6ca5eb54 100644 --- a/src/models/chan.js +++ b/src/models/chan.js @@ -93,8 +93,12 @@ Chan.prototype.sortUsers = function(irc) { }); }; +Chan.prototype.findUser = function(nick) { + return _.find(this.users, {nick: nick}); +}; + Chan.prototype.getMode = function(name) { - var user = _.find(this.users, {nick: name}); + var user = this.findUser(name); if (user) { return user.mode; } diff --git a/src/models/user.js b/src/models/user.js index f1dca1e4..fd6fd25d 100644 --- a/src/models/user.js +++ b/src/models/user.js @@ -8,7 +8,8 @@ function User(attr, prefixLookup) { _.defaults(this, attr, { modes: [], mode: "", - nick: "" + nick: "", + lastMessage: 0, }); // irc-framework sets character mode, but lounge works with symbols @@ -23,5 +24,6 @@ User.prototype.toJSON = function() { return { nick: this.nick, mode: this.mode, + lastMessage: this.lastMessage, }; }; diff --git a/src/plugins/irc-events/message.js b/src/plugins/irc-events/message.js index f83f1b4a..acdd6e61 100644 --- a/src/plugins/irc-events/message.js +++ b/src/plugins/irc-events/message.js @@ -71,6 +71,12 @@ module.exports = function(irc, network) { // Query messages (unless self) always highlight if (chan.type === Chan.Type.QUERY) { highlight = !self; + } else if (chan.type === Chan.Type.CHANNEL) { + const user = chan.findUser(data.nick); + + if (user) { + user.lastMessage = data.time || Date.now(); + } } }