Handle auto completion order on the server

Fixes #289.
This commit is contained in:
Pavel Djundik 2017-07-10 13:56:37 +03:00
parent d839a9e64a
commit 7af573fd96
4 changed files with 19 additions and 19 deletions

View file

@ -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")

View file

@ -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;
}

View file

@ -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,
};
};

View file

@ -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();
}
}
}