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