diff --git a/client/js/socket-events/msg.js b/client/js/socket-events/msg.js index 6712d471..682274a2 100644 --- a/client/js/socket-events/msg.js +++ b/client/js/socket-events/msg.js @@ -89,12 +89,8 @@ socket.on("msg", function (data) { channel.moreHistoryAvailable = true; } - if ((data.msg.type === "message" || data.msg.type === "action") && channel.type === "channel") { - const user = channel.users.find((u) => u.nick === data.msg.from.nick); - - if (user) { - user.lastMessage = new Date(data.msg.time).getTime() || Date.now(); - } + if (channel.type === "channel") { + updateUserList(channel, data.msg); } }); @@ -173,3 +169,25 @@ function notifyMessage(targetId, channel, activeChannel, msg) { } } } + +function updateUserList(channel, msg) { + if (msg.type === "message" || msg.type === "action") { + const user = channel.users.find((u) => u.nick === msg.from.nick); + + if (user) { + user.lastMessage = new Date(msg.time).getTime() || Date.now(); + } + } else if (msg.type === "quit" || msg.type === "part") { + const idx = channel.users.findIndex((u) => u.nick === msg.from.nick); + + if (idx > -1) { + channel.users.splice(idx, 1); + } + } else if (msg.type === "kick") { + const idx = channel.users.findIndex((u) => u.nick === msg.target.nick); + + if (idx > -1) { + channel.users.splice(idx, 1); + } + } +} diff --git a/src/plugins/irc-events/kick.js b/src/plugins/irc-events/kick.js index 6bf5f309..aeac8036 100644 --- a/src/plugins/irc-events/kick.js +++ b/src/plugins/irc-events/kick.js @@ -35,9 +35,5 @@ module.exports = function (irc, network) { } else { chan.removeUser(msg.target); } - - client.emit("users", { - chan: chan.id, - }); }); }; diff --git a/src/plugins/irc-events/part.js b/src/plugins/irc-events/part.js index 8565a0be..a82d4e24 100644 --- a/src/plugins/irc-events/part.js +++ b/src/plugins/irc-events/part.js @@ -33,9 +33,6 @@ module.exports = function (irc, network) { }); } else { chan.removeUser(user); - client.emit("users", { - chan: chan.id, - }); } }); }; diff --git a/src/plugins/irc-events/quit.js b/src/plugins/irc-events/quit.js index 636cae35..36bd336d 100644 --- a/src/plugins/irc-events/quit.js +++ b/src/plugins/irc-events/quit.js @@ -23,9 +23,6 @@ module.exports = function (irc, network) { chan.pushMessage(client, msg); chan.removeUser(user); - client.emit("users", { - chan: chan.id, - }); }); // If user with the nick we are trying to keep has quit, try to get this nick