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 = {
|
|
|
|
updateText
|
|
|
|
};
|
|
|
|
|
|
|
|
function updateText(condensed, addedTypes) {
|
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-08-13 19:09:32 +00:00
|
|
|
addedTypes.forEach((type) => {
|
|
|
|
obj[type]++;
|
|
|
|
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) {
|
|
|
|
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;
|
2017-06-22 20:08:36 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-13 19:09:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
let text = strings.pop();
|
|
|
|
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
|
|
|
}
|