hardlounge/client/js/condensed.js

73 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-06-22 20:08:36 +00:00
"use strict";
const constants = require("./constants");
const templates = require("../views");
2017-06-22 20:08:36 +00:00
module.exports = {
updateText,
getStoredTypes,
2017-06-22 20:08:36 +00:00
};
function getStoredTypes(condensed) {
const obj = {};
2017-06-22 20:08:36 +00:00
constants.condensedTypes.forEach((type) => {
obj[type] = condensed.data(type) || 0;
});
2017-06-22 20:08:36 +00:00
return obj;
}
function updateText(condensed, addedTypes) {
const obj = getStoredTypes(condensed);
Object.keys(addedTypes).map((type) => {
obj[type] += addedTypes[type];
condensed.data(type, obj[type]);
});
2017-06-22 20:08:36 +00:00
2018-04-26 10:16:57 +00:00
// Count quits as parts in condensed messages to reduce information density
obj.part += obj.quit;
const strings = [];
constants.condensedTypes.forEach((type) => {
if (obj[type]) {
switch (type) {
case "away":
strings.push(obj[type] + (obj[type] > 1 ? " users have gone away" : " user has gone away"));
break;
case "back":
strings.push(obj[type] + (obj[type] > 1 ? " users have come back" : " user has come back"));
break;
2017-09-19 15:22:50 +00:00
case "chghost":
strings.push(obj[type] + (obj[type] > 1 ? " users have changed hostname" : " user has changed hostname"));
break;
case "join":
2018-04-24 10:01:20 +00:00
strings.push(obj[type] + (obj[type] > 1 ? " users have joined" : " user has joined"));
break;
case "part":
2018-04-24 10:01:20 +00:00
strings.push(obj[type] + (obj[type] > 1 ? " users have left" : " user has left"));
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;
2017-06-22 20:08:36 +00:00
}
}
});
let text = strings.pop();
if (strings.length) {
text = strings.join(", ") + ", and " + text;
2017-06-22 20:08:36 +00:00
}
condensed.find(".condensed-summary .content")
.html(text + templates.msg_condensed_toggle());
2017-06-22 20:08:36 +00:00
}