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) {
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());
}

View file

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