diff --git a/client/js/condensed.js b/client/js/condensed.js index 8c994742..a7119d1f 100644 --- a/client/js/condensed.js +++ b/client/js/condensed.js @@ -8,32 +8,48 @@ module.exports = { }; function updateText(condensed, addedTypes) { - var obj = {}; + const obj = {}; - for (var i in constants.condensedTypes) { - var msgType = constants.condensedTypes[i]; - obj[msgType] = condensed.data(msgType) || 0; - } + constants.condensedTypes.forEach((type) => { + obj[type] = condensed.data(type) || 0; + }); - for (var k in addedTypes) { - var added = addedTypes[k]; - obj[added]++; - condensed.data(added, obj[added]); - } + addedTypes.forEach((type) => { + obj[type]++; + condensed.data(type, obj[type]); + }); - var text = ""; - - for (var j in constants.condensedTypes) { - var messageType = constants.condensedTypes[j]; - if (obj[messageType]) { - text += text === "" ? "" : ", "; - text += obj[messageType] + " " + messageType; - if (messageType === "nick" || messageType === "mode") { - text += " change"; + const strings = []; + constants.condensedTypes.forEach((type) => { + if (obj[type]) { + switch (type) { + case "join": + strings.push(obj[type] + (obj[type] > 1 ? " users have joined the channel" : " user has joined the channel")); + break; + case "part": + strings.push(obj[type] + (obj[type] > 1 ? " users have left the channel" : " user has left the channel")); + break; + case "quit": + strings.push(obj[type] + (obj[type] > 1 ? " users have quit" : " user has quit")); + break; + case "nick": + strings.push(obj[type] + (obj[type] > 1 ? " users have changed nick" : " user has changed nick")); + break; + case "kick": + strings.push(obj[type] + (obj[type] > 1 ? " users were kicked" : " user was kicked")); + break; + case "mode": + strings.push(obj[type] + (obj[type] > 1 ? " modes were set" : " mode was set")); + break; } - text += obj[messageType] > 1 ? "s" : ""; } + }); + + let text = strings.pop(); + if (strings.length) { + text = strings.join(", ") + ", and " + text; } + condensed.find(".condensed-text") .html(text + templates.msg_condensed_toggle()); } diff --git a/client/js/constants.js b/client/js/constants.js index 0cfb2092..878f0276 100644 --- a/client/js/constants.js +++ b/client/js/constants.js @@ -75,11 +75,11 @@ const actionTypes = [ const condensedTypes = [ "join", - "kick", - "mode", - "nick", "part", "quit", + "nick", + "kick", + "mode", ]; const timeFormats = {