Merge pull request #1865 from thelounge/xpaw/proper-msg-from-fix

Correctly fix `from` field in messages
This commit is contained in:
Al McKinlay 2017-12-20 12:07:48 +00:00 committed by GitHub
commit 96adc56cd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 12 deletions

View File

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