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) { function handleMessage(data) {
let chan; let chan;
const from = chan.getUser(data.nick); let from;
const msg = new Msg({ let highlight = false;
type: data.type, let showInActive = false;
time: data.time, const self = data.nick === irc.user.nick;
text: data.message,
self: data.nick === irc.user.nick,
from: from,
highlight: false,
users: [],
});
// Server messages go to server window, no questions asked // Server messages go to server window, no questions asked
if (data.from_server) { if (data.from_server) {
chan = network.channels[0]; chan = network.channels[0];
from = chan.getUser(data.nick);
} else { } else {
let target = data.target; let target = data.target;
@ -65,7 +60,7 @@ module.exports = function(irc, network) {
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
// Send notices that are not targeted at us into the server window // Send notices that are not targeted at us into the server window
if (data.type === Msg.Type.NOTICE) { if (data.type === Msg.Type.NOTICE) {
msg.showInActive = true; showInActive = true;
chan = network.channels[0]; chan = network.channels[0];
} else { } else {
chan = new Chan({ chan = new Chan({
@ -80,14 +75,31 @@ module.exports = function(irc, network) {
} }
} }
from = chan.getUser(data.nick);
// Query messages (unless self) always highlight // Query messages (unless self) always highlight
if (chan.type === Chan.Type.QUERY) { if (chan.type === Chan.Type.QUERY) {
msg.highlight = !msg.self; highlight = !self;
} else if (chan.type === Chan.Type.CHANNEL) { } else if (chan.type === Chan.Type.CHANNEL) {
from.lastMessage = data.time || Date.now(); 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 // Self messages in channels are never highlighted
// Non-self messages are highlighted as soon as the nick is detected // Non-self messages are highlighted as soon as the nick is detected
if (!msg.highlight && !msg.self) { if (!msg.highlight && !msg.self) {