webui: unread chat message counter in menu

This commit is contained in:
zeners 2016-03-12 20:20:56 +01:00
parent e9af1794dd
commit 0afa2e3726
3 changed files with 39 additions and 1 deletions

View File

@ -54,5 +54,5 @@ should provide forward, backward and follow-list-end
need 4 master need 4 master
------------- -------------
[ ] unsubscribe lobby [ ] unsubscribe lobby
[ ] unread chat message counter in menu [X] unread chat message counter in menu
[ ] list chat-lobby participants [ ] list chat-lobby participants

View File

@ -70,6 +70,24 @@ module.exports = { nodes: [
{ {
name: "chat", name: "chat",
runstate: "running_ok.*", runstate: "running_ok.*",
counter: rs.counting2([
{
path: "peers",
counter: function(peer) {
var sum = 0;
peer.locations.map(function (loc) {
sum += parseInt(loc.unread_msgs);
});
return sum;
}
},
{
path: "chat/lobbies",
counter: function(lobby) {
return lobby.unread_msg_count;
}
}
])
}, },
{ {
name: "shutdown", name: "shutdown",

View File

@ -282,6 +282,26 @@ rs.counting = function(path, counterfnkt) {
} }
}; };
// counting in menu
rs.counting2 = function(targets) {
return function () {
var sum = 0;
targets.map(function(target) {
var data=rs(target.path);
if (data != undefined) {
data.map(function(item){
sum += parseInt(target.counter(item));
});
};
return null;
});
if (sum > 0) {
return " (" + sum + ")";
}
return "";
}
};
// listing data-elements // listing data-elements
rs.list = function(path, buildfktn, sortfktn){ rs.list = function(path, buildfktn, sortfktn){
var list = rs(path); var list = rs(path);