Merge pull request #1698 from thelounge/xpaw/refactor-user-msgs

Refactor how user object is sent to the client
This commit is contained in:
Pavel Djundik 2017-11-19 11:25:33 +02:00 committed by GitHub
commit 56a9ad184d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 191 additions and 175 deletions

View File

@ -1,4 +1,4 @@
{{> ../user_name nick=from}} {{> ../user_name from}}
<span class="text">{{{parse text}}}</span> <span class="text">{{{parse text}}}</span>
{{#each previews}} {{#each previews}}

View File

@ -1,3 +1,3 @@
{{> ../user_name nick=from}} {{> ../user_name from}}
is away is away
<i class="away-message">({{{parse text}}})</i> <i class="away-message">({{{parse text}}})</i>

View File

@ -1,2 +1,2 @@
{{> ../user_name nick=from}} {{> ../user_name from}}
is back is back

View File

@ -1,2 +1,2 @@
{{> ../user_name nick=from}} {{> ../user_name from}}
<b>{{ctcpType}}</b> <span class="ctcp-message">{{{parse ctcpMessage}}}</span> <b>{{ctcpType}}</b> <span class="ctcp-message">{{{parse ctcpMessage}}}</span>

View File

@ -1,9 +1,9 @@
{{> ../user_name nick=from}} {{> ../user_name from}}
invited invited
{{#if invitedYou}} {{#if invitedYou}}
you you
{{else}} {{else}}
{{> ../user_name nick=invited}} {{> ../user_name invited}}
{{/if}} {{/if}}
to to
{{{parse channel}}} {{{parse channel}}}

View File

@ -1,3 +1,3 @@
{{> ../user_name nick=from}} {{> ../user_name from}}
<i class="hostmask">({{hostmask}})</i> <i class="hostmask">({{hostmask}})</i>
has joined the channel has joined the channel

View File

@ -1,6 +1,6 @@
{{> ../user_name nick=from.nick mode=from.mode}} {{> ../user_name from}}
has kicked has kicked
{{> ../user_name nick=target.nick mode=target.mode}} {{> ../user_name target}}
{{#if text}} {{#if text}}
<i class="part-reason">({{{parse text}}})</i> <i class="part-reason">({{{parse text}}})</i>
{{/if}} {{/if}}

View File

@ -1,3 +1,3 @@
{{> ../user_name nick=from}} {{> ../user_name from}}
sets mode sets mode
{{{parse text}}} {{{parse text}}}

View File

@ -1,3 +1,3 @@
{{> ../user_name nick=from}} {{> ../user_name from}}
is now known as is now known as
{{> ../user_name nick=new_nick}} {{> ../user_name nick=new_nick mode=from.mode}}

View File

@ -1,4 +1,4 @@
{{> ../user_name nick=from}} {{> ../user_name from}}
<i class="hostmask">({{hostmask}})</i> <i class="hostmask">({{hostmask}})</i>
has left the channel has left the channel
{{#if text}} {{#if text}}

View File

@ -1,4 +1,4 @@
{{> ../user_name nick=from}} {{> ../user_name from}}
<i class="hostmask">({{hostmask}})</i> <i class="hostmask">({{hostmask}})</i>
has quit has quit
{{#if text}} {{#if text}}

View File

@ -1,5 +1,5 @@
{{#if from}} {{#if from}}
{{> ../user_name nick=from}} {{> ../user_name from}}
has changed the topic to: has changed the topic to:
{{else}} {{else}}
The topic is: The topic is:

View File

@ -1,3 +1,3 @@
Topic set by Topic set by
{{> ../user_name}} {{> ../user_name from}}
on {{localetime when}} on {{localetime when}}

View File

@ -4,7 +4,7 @@
</span> </span>
<span class="from"> <span class="from">
{{#if from}} {{#if from}}
{{> user_name nick=from}} {{> user_name from}}
{{/if}} {{/if}}
</span> </span>
<span class="content"> <span class="content">

View File

@ -126,15 +126,6 @@ Chan.prototype.getUser = function(nick) {
return this.findUser(nick) || new User({nick: nick}); return this.findUser(nick) || new User({nick: nick});
}; };
Chan.prototype.getMode = function(name) {
var user = this.findUser(name);
if (user) {
return user.mode;
}
return "";
};
Chan.prototype.toJSON = function() { Chan.prototype.toJSON = function() {
var clone = _.clone(this); var clone = _.clone(this);
clone.users = []; // Do not send user list, the client will explicitly request it when needed clone.users = []; // Do not send user list, the client will explicitly request it when needed

View File

@ -19,8 +19,7 @@ module.exports = function(irc, network) {
type: away ? Msg.Type.AWAY : Msg.Type.BACK, type: away ? Msg.Type.AWAY : Msg.Type.BACK,
text: away || "", text: away || "",
time: data.time, time: data.time,
from: data.nick, from: user,
mode: user.mode,
}); });
chan.pushMessage(client, msg); chan.pushMessage(client, msg);

View File

@ -1,12 +1,12 @@
"use strict"; "use strict";
var _ = require("lodash"); const _ = require("lodash");
var Msg = require("../../models/msg"); const Msg = require("../../models/msg");
var Chan = require("../../models/chan"); const Chan = require("../../models/chan");
var Helper = require("../../helper"); const Helper = require("../../helper");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; const client = this;
network.channels[0].pushMessage(client, new Msg({ network.channels[0].pushMessage(client, new Msg({
text: "Network created, connecting to " + network.host + ":" + network.port + "...", text: "Network created, connecting to " + network.host + ":" + network.port + "...",
@ -27,10 +27,10 @@ module.exports = function(irc, network) {
irc.raw("AWAY", client.awayMessage); irc.raw("AWAY", client.awayMessage);
} }
var delay = 1000; let delay = 1000;
var commands = network.commands;
if (Array.isArray(commands)) { if (Array.isArray(network.commands)) {
commands.forEach((cmd) => { network.commands.forEach((cmd) => {
setTimeout(function() { setTimeout(function() {
client.input({ client.input({
target: network.channels[0].id, target: network.channels[0].id,

View File

@ -7,6 +7,7 @@ module.exports = function(irc, network) {
irc.on("ctcp response", function(data) { irc.on("ctcp response", function(data) {
let chan = network.getChannel(data.nick); let chan = network.getChannel(data.nick);
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
chan = network.channels[0]; chan = network.channels[0];
} }
@ -14,7 +15,7 @@ module.exports = function(irc, network) {
const msg = new Msg({ const msg = new Msg({
type: Msg.Type.CTCP, type: Msg.Type.CTCP,
time: data.time, time: data.time,
from: data.nick, from: chan.getUser(data.nick),
ctcpType: data.type, ctcpType: data.type,
ctcpMessage: data.message, ctcpMessage: data.message,
}); });

View File

@ -1,17 +1,19 @@
"use strict"; "use strict";
var Msg = require("../../models/msg"); const Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; const client = this;
irc.on("irc error", function(data) { irc.on("irc error", function(data) {
var text = data.error; let text = data.error;
if (data.reason) { if (data.reason) {
text = data.reason + " (" + text + ")"; text = data.reason + " (" + text + ")";
} }
var lobby = network.channels[0];
var msg = new Msg({ const lobby = network.channels[0];
const msg = new Msg({
type: Msg.Type.ERROR, type: Msg.Type.ERROR,
text: text, text: text,
}); });
@ -19,15 +21,15 @@ module.exports = function(irc, network) {
}); });
irc.on("nick in use", function(data) { irc.on("nick in use", function(data) {
var lobby = network.channels[0]; const lobby = network.channels[0];
var msg = new Msg({ const msg = new Msg({
type: Msg.Type.ERROR, type: Msg.Type.ERROR,
text: data.nick + ": " + (data.reason || "Nickname is already in use."), text: data.nick + ": " + (data.reason || "Nickname is already in use."),
}); });
lobby.pushMessage(client, msg, true); lobby.pushMessage(client, msg, true);
if (irc.connection.registered === false) { if (irc.connection.registered === false) {
var random = (data.nick || irc.user.nick) + Math.floor(10 + (Math.random() * 89)); const random = (data.nick || irc.user.nick) + Math.floor(10 + (Math.random() * 89));
irc.changeNick(random); irc.changeNick(random);
} }
@ -38,15 +40,15 @@ module.exports = function(irc, network) {
}); });
irc.on("nick invalid", function(data) { irc.on("nick invalid", function(data) {
var lobby = network.channels[0]; const lobby = network.channels[0];
var msg = new Msg({ const msg = new Msg({
type: Msg.Type.ERROR, type: Msg.Type.ERROR,
text: data.nick + ": " + (data.reason || "Nickname is invalid."), text: data.nick + ": " + (data.reason || "Nickname is invalid."),
}); });
lobby.pushMessage(client, msg, true); lobby.pushMessage(client, msg, true);
if (irc.connection.registered === false) { if (irc.connection.registered === false) {
var random = "i" + Math.random().toString(36).substr(2, 10); // 'i' so it never begins with a number const random = "i" + Math.random().toString(36).substr(2, 10); // 'i' so it never begins with a number
irc.changeNick(random); irc.changeNick(random);
} }

View File

@ -1,20 +1,22 @@
"use strict"; "use strict";
var Msg = require("../../models/msg"); const Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; const client = this;
irc.on("invite", function(data) { irc.on("invite", function(data) {
var chan = network.getChannel(data.channel); let chan = network.getChannel(data.channel);
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
chan = network.channels[0]; chan = network.channels[0];
} }
var msg = new Msg({ const msg = new Msg({
type: Msg.Type.INVITE, type: Msg.Type.INVITE,
time: data.time, time: data.time,
from: data.nick, from: chan.getUser(data.nick),
invited: data.invited, invited: chan.getUser(data.invited),
channel: data.channel, channel: data.channel,
highlight: true, highlight: true,
invitedYou: data.invited === irc.user.nick, invitedYou: data.invited === irc.user.nick,

View File

@ -1,13 +1,15 @@
"use strict"; "use strict";
var Chan = require("../../models/chan"); const Chan = require("../../models/chan");
var Msg = require("../../models/msg"); const Msg = require("../../models/msg");
var User = require("../../models/user"); const User = require("../../models/user");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; const client = this;
irc.on("join", function(data) { irc.on("join", function(data) {
var chan = network.getChannel(data.channel); let chan = network.getChannel(data.channel);
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
chan = new Chan({ chan = new Chan({
name: data.channel, name: data.channel,
@ -22,18 +24,21 @@ module.exports = function(irc, network) {
// Request channels' modes // Request channels' modes
network.irc.raw("MODE", chan.name); network.irc.raw("MODE", chan.name);
} }
chan.users.push(new User({nick: data.nick}));
chan.sortUsers(irc); const user = new User({nick: data.nick});
client.emit("users", { const msg = new Msg({
chan: chan.id,
});
var msg = new Msg({
time: data.time, time: data.time,
from: data.nick, from: user,
hostmask: data.ident + "@" + data.hostname, hostmask: data.ident + "@" + data.hostname,
type: Msg.Type.JOIN, type: Msg.Type.JOIN,
self: data.nick === irc.user.nick, self: data.nick === irc.user.nick,
}); });
chan.pushMessage(client, msg); chan.pushMessage(client, msg);
chan.users.push(user);
chan.sortUsers(irc);
client.emit("users", {
chan: chan.id,
});
}); });
}; };

View File

@ -1,38 +1,37 @@
"use strict"; "use strict";
var _ = require("lodash"); const _ = require("lodash");
var Msg = require("../../models/msg"); const Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; const client = this;
irc.on("kick", function(data) { irc.on("kick", function(data) {
var chan = network.getChannel(data.channel); const chan = network.getChannel(data.channel);
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
return; return;
} }
const kicker = chan.getUser(data.nick); const msg = new Msg({
const target = chan.getUser(data.kicked);
if (data.kicked === irc.user.nick) {
chan.users = [];
} else {
chan.users = _.without(chan.users, target);
}
client.emit("users", {
chan: chan.id,
});
var msg = new Msg({
type: Msg.Type.KICK, type: Msg.Type.KICK,
time: data.time, time: data.time,
from: kicker, from: chan.getUser(data.nick),
target: target, target: chan.getUser(data.kicked),
text: data.message || "", text: data.message || "",
highlight: data.kicked === irc.user.nick, highlight: data.kicked === irc.user.nick,
self: data.nick === irc.user.nick, self: data.nick === irc.user.nick,
}); });
chan.pushMessage(client, msg); chan.pushMessage(client, msg);
if (data.kicked === irc.user.nick) {
chan.users = [];
} else {
chan.users = _.without(chan.users, msg.target);
}
client.emit("users", {
chan: chan.id,
});
}); });
}; };

View File

@ -154,9 +154,11 @@ function fetch(uri, cb) {
} catch (e) { } catch (e) {
return cb(null); return cb(null);
} }
const buffers = []; const buffers = [];
var length = 0; let length = 0;
var limit = Helper.config.prefetchMaxImageSize * 1024; let limit = Helper.config.prefetchMaxImageSize * 1024;
req req
.on("response", function(res) { .on("response", function(res) {
if (/^image\/.+/.test(res.headers["content-type"])) { if (/^image\/.+/.test(res.headers["content-type"])) {

View File

@ -1,11 +1,11 @@
"use strict"; "use strict";
var Chan = require("../../models/chan"); const Chan = require("../../models/chan");
var Msg = require("../../models/msg"); const Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; const client = this;
var MAX_CHANS = 500; const MAX_CHANS = 500;
irc.on("channel list start", function() { irc.on("channel list start", function() {
network.chanCache = []; network.chanCache = [];
@ -39,7 +39,8 @@ module.exports = function(irc, network) {
}); });
function updateListStatus(msg) { function updateListStatus(msg) {
var chan = network.getChannel("Channel List"); let chan = network.getChannel("Channel List");
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
chan = new Chan({ chan = new Chan({
type: Chan.Type.SPECIAL, type: Chan.Type.SPECIAL,

View File

@ -6,7 +6,7 @@ const LinkPrefetch = require("./link");
const Helper = require("../../helper"); const Helper = require("../../helper");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; const client = this;
irc.on("notice", function(data) { irc.on("notice", function(data) {
// Some servers send notices without any nickname // Some servers send notices without any nickname
@ -37,14 +37,16 @@ module.exports = function(irc, network) {
function handleMessage(data) { function handleMessage(data) {
let chan; let chan;
let user;
let highlight = false; let highlight = false;
const self = data.nick === irc.user.nick; const self = data.nick === irc.user.nick;
// 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];
user = chan.getUser(data.nick);
} else { } else {
var target = data.target; let target = data.target;
// If the message is targeted at us, use sender as target instead // If the message is targeted at us, use sender as target instead
if (target.toLowerCase() === irc.user.nick.toLowerCase()) { if (target.toLowerCase() === irc.user.nick.toLowerCase()) {
@ -52,6 +54,7 @@ module.exports = function(irc, network) {
} }
chan = network.getChannel(target); chan = network.getChannel(target);
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) {
@ -69,17 +72,15 @@ module.exports = function(irc, network) {
} }
} }
user = 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) {
highlight = !self; highlight = !self;
} else if (chan.type === Chan.Type.CHANNEL) { } else if (chan.type === Chan.Type.CHANNEL) {
const user = chan.findUser(data.nick);
if (user) {
user.lastMessage = data.time || Date.now(); user.lastMessage = data.time || Date.now();
} }
} }
}
// 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
@ -87,11 +88,10 @@ module.exports = function(irc, network) {
highlight = network.highlightRegex.test(data.message); highlight = network.highlightRegex.test(data.message);
} }
var msg = new Msg({ const msg = new Msg({
type: data.type, type: data.type,
time: data.time, time: data.time,
mode: chan.getMode(data.nick), from: user,
from: data.nick,
text: data.message, text: data.message,
self: self, self: self,
highlight: highlight, highlight: highlight,

View File

@ -1,7 +1,6 @@
"use strict"; "use strict";
const _ = require("lodash"); const _ = require("lodash");
const Chan = require("../../models/chan");
const Msg = require("../../models/msg"); const Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
@ -70,8 +69,7 @@ module.exports = function(irc, network) {
const msg = new Msg({ const msg = new Msg({
time: data.time, time: data.time,
type: Msg.Type.MODE, type: Msg.Type.MODE,
mode: (targetChan.type !== Chan.Type.LOBBY && targetChan.getMode(data.nick)) || "", from: targetChan.getUser(data.nick),
from: data.nick,
text: text, text: text,
self: data.nick === irc.user.nick, self: data.nick === irc.user.nick,
}); });

View File

@ -1,15 +1,16 @@
"use strict"; "use strict";
var Msg = require("../../models/msg"); const Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; const client = this;
irc.on("motd", function(data) { irc.on("motd", function(data) {
var lobby = network.channels[0]; const lobby = network.channels[0];
if (data.motd) { if (data.motd) {
data.motd.split("\n").forEach((text) => { data.motd.split("\n").forEach((text) => {
var msg = new Msg({ const msg = new Msg({
type: Msg.Type.MOTD, type: Msg.Type.MOTD,
text: text, text: text,
}); });
@ -18,7 +19,7 @@ module.exports = function(irc, network) {
} }
if (data.error) { if (data.error) {
var msg = new Msg({ const msg = new Msg({
type: Msg.Type.MOTD, type: Msg.Type.MOTD,
text: data.error, text: data.error,
}); });

View File

@ -1,21 +1,23 @@
"use strict"; "use strict";
var Msg = require("../../models/msg"); const Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; const client = this;
irc.on("nick", function(data) { irc.on("nick", function(data) {
let msg; let msg;
var self = false; const self = data.nick === irc.user.nick;
if (data.nick === irc.user.nick) {
if (self) {
network.setNick(data.new_nick); network.setNick(data.new_nick);
var lobby = network.channels[0]; const lobby = network.channels[0];
msg = new Msg({ msg = new Msg({
text: "You're now known as " + data.new_nick, text: `You're now known as ${data.new_nick}`,
}); });
lobby.pushMessage(client, msg, true); lobby.pushMessage(client, msg, true);
self = true;
client.save(); client.save();
client.emit("nick", { client.emit("nick", {
network: network.id, network: network.id,
@ -25,23 +27,26 @@ module.exports = function(irc, network) {
network.channels.forEach((chan) => { network.channels.forEach((chan) => {
const user = chan.findUser(data.nick); const user = chan.findUser(data.nick);
if (typeof user === "undefined") { if (typeof user === "undefined") {
return; return;
} }
user.nick = data.new_nick;
chan.sortUsers(irc);
client.emit("users", {
chan: chan.id,
});
msg = new Msg({ msg = new Msg({
time: data.time, time: data.time,
from: data.nick, from: user,
type: Msg.Type.NICK, type: Msg.Type.NICK,
mode: chan.getMode(data.new_nick),
new_nick: data.new_nick, new_nick: data.new_nick,
self: self, self: self,
}); });
chan.pushMessage(client, msg); chan.pushMessage(client, msg);
user.nick = data.new_nick;
chan.sortUsers(irc);
client.emit("users", {
chan: chan.id,
});
}); });
}); });
}; };

View File

@ -1,17 +1,19 @@
"use strict"; "use strict";
var _ = require("lodash"); const _ = require("lodash");
var Msg = require("../../models/msg"); const Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; const client = this;
irc.on("part", function(data) { irc.on("part", function(data) {
var chan = network.getChannel(data.channel); const chan = network.getChannel(data.channel);
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
return; return;
} }
var from = data.nick;
if (from === irc.user.nick) { if (data.nick === irc.user.nick) {
network.channels = _.without(network.channels, chan); network.channels = _.without(network.channels, chan);
chan.destroy(); chan.destroy();
client.save(); client.save();
@ -19,20 +21,21 @@ module.exports = function(irc, network) {
chan: chan.id, chan: chan.id,
}); });
} else { } else {
const user = chan.findUser(from); const user = chan.getUser(data.nick);
const msg = new Msg({
type: Msg.Type.PART,
time: data.time,
text: data.message || "",
hostmask: data.ident + "@" + data.hostname,
from: user,
});
chan.pushMessage(client, msg);
chan.users = _.without(chan.users, user); chan.users = _.without(chan.users, user);
client.emit("users", { client.emit("users", {
chan: chan.id, chan: chan.id,
}); });
var msg = new Msg({
type: Msg.Type.PART,
time: data.time,
mode: (user && user.mode) || "",
text: data.message || "",
hostmask: data.ident + "@" + data.hostname,
from: from,
});
chan.pushMessage(client, msg);
} }
}); });
}; };

View File

@ -1,29 +1,32 @@
"use strict"; "use strict";
var _ = require("lodash"); const _ = require("lodash");
var Msg = require("../../models/msg"); const Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; const client = this;
irc.on("quit", function(data) { irc.on("quit", function(data) {
network.channels.forEach((chan) => { network.channels.forEach((chan) => {
const user = chan.findUser(data.nick); const user = chan.findUser(data.nick);
if (typeof user === "undefined") { if (typeof user === "undefined") {
return; return;
} }
const msg = new Msg({
time: data.time,
type: Msg.Type.QUIT,
text: data.message || "",
hostmask: data.ident + "@" + data.hostname,
from: user,
});
chan.pushMessage(client, msg);
chan.users = _.without(chan.users, user); chan.users = _.without(chan.users, user);
client.emit("users", { client.emit("users", {
chan: chan.id, chan: chan.id,
}); });
var msg = new Msg({
time: data.time,
type: Msg.Type.QUIT,
mode: user.mode || "",
text: data.message || "",
hostmask: data.ident + "@" + data.hostname,
from: data.nick,
});
chan.pushMessage(client, msg);
}); });
}); });
}; };

View File

@ -1,20 +1,21 @@
"use strict"; "use strict";
var Msg = require("../../models/msg"); const Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; const client = this;
irc.on("topic", function(data) { irc.on("topic", function(data) {
var chan = network.getChannel(data.channel); const chan = network.getChannel(data.channel);
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
return; return;
} }
var msg = new Msg({ const msg = new Msg({
time: data.time, time: data.time,
type: Msg.Type.TOPIC, type: Msg.Type.TOPIC,
mode: (data.nick && chan.getMode(data.nick)) || "", from: chan.getUser(data.nick),
from: data.nick,
text: data.topic, text: data.topic,
self: data.nick === irc.user.nick, self: data.nick === irc.user.nick,
}); });
@ -28,15 +29,15 @@ module.exports = function(irc, network) {
}); });
irc.on("topicsetby", function(data) { irc.on("topicsetby", function(data) {
var chan = network.getChannel(data.channel); const chan = network.getChannel(data.channel);
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
return; return;
} }
var msg = new Msg({ const msg = new Msg({
type: Msg.Type.TOPIC_SET_BY, type: Msg.Type.TOPIC_SET_BY,
mode: chan.getMode(data.nick), from: chan.getUser(data.nick),
nick: data.nick,
when: new Date(data.when * 1000), when: new Date(data.when * 1000),
self: data.nick === irc.user.nick, self: data.nick === irc.user.nick,
}); });

View File

@ -1,9 +1,9 @@
"use strict"; "use strict";
var Msg = require("../../models/msg"); const Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; const client = this;
irc.on("unknown command", function(command) { irc.on("unknown command", function(command) {
// Do not display users own name // Do not display users own name

View File

@ -1,17 +1,19 @@
"use strict"; "use strict";
var Msg = require("../../models/msg"); const Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; const client = this;
irc.on("registered", function(data) { irc.on("registered", function(data) {
network.setNick(data.nick); network.setNick(data.nick);
var lobby = network.channels[0]; const lobby = network.channels[0];
var msg = new Msg({ const msg = new Msg({
text: "You're now known as " + data.nick, text: "You're now known as " + data.nick,
}); });
lobby.pushMessage(client, msg); lobby.pushMessage(client, msg);
client.save(); client.save();
client.emit("nick", { client.emit("nick", {
network: network.id, network: network.id,

View File

@ -1,12 +1,13 @@
"use strict"; "use strict";
var Chan = require("../../models/chan"); const Chan = require("../../models/chan");
var Msg = require("../../models/msg"); const Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; const client = this;
irc.on("whois", function(data) { irc.on("whois", function(data) {
var chan = network.getChannel(data.nick); let chan = network.getChannel(data.nick);
if (typeof chan === "undefined") { if (typeof chan === "undefined") {
chan = new Chan({ chan = new Chan({
type: Chan.Type.QUERY, type: Chan.Type.QUERY,
@ -20,7 +21,7 @@ module.exports = function(irc, network) {
}); });
} }
var msg; let msg;
if (data.error) { if (data.error) {
msg = new Msg({ msg = new Msg({
type: Msg.Type.ERROR, type: Msg.Type.ERROR,