Merge pull request #1495 from thelounge/xpaw/only-order-autocomplete-on-msg

Only change nick autocompletion when receiving a message
This commit is contained in:
Jérémie Astori 2017-09-05 19:50:08 -04:00 committed by GitHub
commit 87d6918358
2 changed files with 15 additions and 27 deletions

View File

@ -36,7 +36,7 @@ function buildChannelMessages(chanId, chanType, messages) {
function appendMessage(container, chanId, chanType, msg) { function appendMessage(container, chanId, chanType, msg) {
let lastChild = container.children(".msg, .date-marker-container").last(); let lastChild = container.children(".msg, .date-marker-container").last();
const renderedMessage = buildChatMessage(chanId, msg); const renderedMessage = buildChatMessage(msg);
// Check if date changed // Check if date changed
const msgTime = new Date(msg.time); const msgTime = new Date(msg.time);
@ -44,7 +44,7 @@ function appendMessage(container, chanId, chanType, msg) {
// Insert date marker if date changed compared to previous message // Insert date marker if date changed compared to previous message
if (prevMsgTime.toDateString() !== msgTime.toDateString()) { if (prevMsgTime.toDateString() !== msgTime.toDateString()) {
lastChild = $(templates.date_marker({msgDate: msg.time})); lastChild = $(templates.date_marker({time: msg.time}));
container.append(lastChild); container.append(lastChild);
} }
@ -64,25 +64,15 @@ function appendMessage(container, chanId, chanType, msg) {
} }
// Always create a condensed container // Always create a condensed container
const newCondensed = buildChatMessage(chanId, { const newCondensed = $(templates.msg_condensed({time: msg.time}));
type: "condensed",
time: msg.time,
previews: []
});
condensed.updateText(newCondensed, [msg.type]); condensed.updateText(newCondensed, [msg.type]);
newCondensed.append(renderedMessage); newCondensed.append(renderedMessage);
container.append(newCondensed); container.append(newCondensed);
} }
function buildChatMessage(chanId, msg) { function buildChatMessage(msg) {
const type = msg.type; const type = msg.type;
let target = "#chan-" + chanId;
if (type === "error") {
target = "#chan-" + chat.find(".active").data("id");
}
const chan = chat.find(target);
let template = "msg"; let template = "msg";
// See if any of the custom highlight regexes match // See if any of the custom highlight regexes match
@ -98,8 +88,6 @@ function buildChatMessage(chanId, msg) {
template = "msg_action"; template = "msg_action";
} else if (type === "unhandled") { } else if (type === "unhandled") {
template = "msg_unhandled"; template = "msg_unhandled";
} else if (type === "condensed") {
template = "msg_condensed";
} }
const renderedMessage = $(templates[template](msg)); const renderedMessage = $(templates[template](msg));
@ -113,17 +101,6 @@ function buildChatMessage(chanId, msg) {
renderPreview(preview, renderedMessage); renderPreview(preview, renderedMessage);
}); });
if ((type === "message" || type === "action" || type === "notice") && chan.hasClass("channel")) {
const nicks = chan.find(".users").data("nicks");
if (nicks) {
const find = nicks.indexOf(msg.from);
if (find !== -1) {
nicks.splice(find, 1);
nicks.unshift(msg.from);
}
}
}
return renderedMessage; return renderedMessage;
} }

View File

@ -63,4 +63,15 @@ function processReceivedMessage(data) {
} }
}); });
} }
if ((data.msg.type === "message" || data.msg.type === "action" || data.msg.type === "notice") && channel.hasClass("channel")) {
const nicks = channel.find(".users").data("nicks");
if (nicks) {
const find = nicks.indexOf(data.msg.from);
if (find !== -1) {
nicks.splice(find, 1);
nicks.unshift(data.msg.from);
}
}
}
} }