Merge pull request #3857 from thelounge/xpaw/optimize-userlist-updates

Optimize user list updates for quit/part/kick events
This commit is contained in:
Pavel Djundik 2020-04-13 11:39:57 +03:00 committed by GitHub
commit 1754c77517
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 16 deletions

View File

@ -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);
}
}
}

View File

@ -35,9 +35,5 @@ module.exports = function (irc, network) {
} else {
chan.removeUser(msg.target);
}
client.emit("users", {
chan: chan.id,
});
});
};

View File

@ -33,9 +33,6 @@ module.exports = function (irc, network) {
});
} else {
chan.removeUser(user);
client.emit("users", {
chan: chan.id,
});
}
});
};

View File

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