Add some human-friendliness to the condensed status messages

This commit is contained in:
Jérémie Astori 2017-08-13 15:09:32 -04:00
parent 853e646670
commit 43a8604b32
No known key found for this signature in database
GPG Key ID: B9A4F245CD67BDE8
2 changed files with 39 additions and 23 deletions

View File

@ -8,32 +8,48 @@ module.exports = {
}; };
function updateText(condensed, addedTypes) { function updateText(condensed, addedTypes) {
var obj = {}; const obj = {};
for (var i in constants.condensedTypes) { constants.condensedTypes.forEach((type) => {
var msgType = constants.condensedTypes[i]; obj[type] = condensed.data(type) || 0;
obj[msgType] = condensed.data(msgType) || 0; });
}
for (var k in addedTypes) { addedTypes.forEach((type) => {
var added = addedTypes[k]; obj[type]++;
obj[added]++; condensed.data(type, obj[type]);
condensed.data(added, obj[added]); });
}
var text = ""; const strings = [];
constants.condensedTypes.forEach((type) => {
for (var j in constants.condensedTypes) { if (obj[type]) {
var messageType = constants.condensedTypes[j]; switch (type) {
if (obj[messageType]) { case "join":
text += text === "" ? "" : ", "; strings.push(obj[type] + (obj[type] > 1 ? " users have joined the channel" : " user has joined the channel"));
text += obj[messageType] + " " + messageType; break;
if (messageType === "nick" || messageType === "mode") { case "part":
text += " change"; 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") condensed.find(".condensed-text")
.html(text + templates.msg_condensed_toggle()); .html(text + templates.msg_condensed_toggle());
} }

View File

@ -75,11 +75,11 @@ const actionTypes = [
const condensedTypes = [ const condensedTypes = [
"join", "join",
"kick",
"mode",
"nick",
"part", "part",
"quit", "quit",
"nick",
"kick",
"mode",
]; ];
const timeFormats = { const timeFormats = {