From dc8c10f46181e466e7f540ac16e3acaa26f610ce Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 20 Dec 2017 13:45:17 +0200 Subject: [PATCH] Correctly fix `from` field in messages This should have been in #1859 --- src/plugins/irc-events/message.js | 36 ++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/plugins/irc-events/message.js b/src/plugins/irc-events/message.js index 3e0d4046..40bb04c7 100644 --- a/src/plugins/irc-events/message.js +++ b/src/plugins/irc-events/message.js @@ -38,20 +38,15 @@ module.exports = function(irc, network) { function handleMessage(data) { let chan; - const from = chan.getUser(data.nick); - const msg = new Msg({ - type: data.type, - time: data.time, - text: data.message, - self: data.nick === irc.user.nick, - from: from, - highlight: false, - users: [], - }); + let from; + let highlight = false; + let showInActive = false; + const self = data.nick === irc.user.nick; // Server messages go to server window, no questions asked if (data.from_server) { chan = network.channels[0]; + from = chan.getUser(data.nick); } else { let target = data.target; @@ -65,7 +60,7 @@ module.exports = function(irc, network) { if (typeof chan === "undefined") { // Send notices that are not targeted at us into the server window if (data.type === Msg.Type.NOTICE) { - msg.showInActive = true; + showInActive = true; chan = network.channels[0]; } else { chan = new Chan({ @@ -80,14 +75,31 @@ module.exports = function(irc, network) { } } + from = chan.getUser(data.nick); + // Query messages (unless self) always highlight if (chan.type === Chan.Type.QUERY) { - msg.highlight = !msg.self; + highlight = !self; } else if (chan.type === Chan.Type.CHANNEL) { from.lastMessage = data.time || Date.now(); } } + // msg is constructed down here because `from` is being copied in the constructor + const msg = new Msg({ + type: data.type, + time: data.time, + text: data.message, + self: self, + from: from, + highlight: highlight, + users: [], + }); + + if (showInActive) { + msg.showInActive = true; + } + // Self messages in channels are never highlighted // Non-self messages are highlighted as soon as the nick is detected if (!msg.highlight && !msg.self) {