From ec724893002029b032976370172250f81780e581 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 24 Aug 2013 17:39:04 +0000 Subject: [PATCH] do [#568] --- modules/report/pages.js | 64 ++++++++++++++++++++++++++++++++-------- modules/report/report.js | 2 +- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/modules/report/pages.js b/modules/report/pages.js index 45aaecd..e766643 100644 --- a/modules/report/pages.js +++ b/modules/report/pages.js @@ -1,20 +1,46 @@ -var _ = require('underscore')._; +var _ = require('underscore')._, + async = require('async'); var pages = function(dbot) { var pages = { '/notify': function(req, res) { res.render('servers', { - 'name': dbot.config.name, 'servers': _.keys(dbot.config.servers) }); }, '/notify/:server': function(req, res) { - var server = req.params.server; - res.render('channels', { - 'name': dbot.config.name, - 'server': server, - 'channels': _.keys(dbot.instance.connections[server].channels) + var server = req.params.server, + userCount = {}, + users = []; + + this.db.scan('notifies', function(notify) { + if(!_.has(userCount, notify.user)) { + userCount[notify.user] = 0; + } else { + userCount[notify.user]++; + } + }, function() { + userCount = _.map(userCount, function(value, key) { + return { + 'id': key, + 'count': value + } + }); + + async.eachSeries(userCount, function(userCount, next) { + dbot.api.users.getUser(userCount.id, function(user) { + userCount['name'] = user.primaryNick; + users.push(userCount); + next(); + }); + }, function() { + res.render('channels', { + 'server': server, + 'users': users, + 'channels': _.keys(dbot.instance.connections[server].channels) + }); + }); }); }, @@ -23,8 +49,9 @@ var pages = function(dbot) { user = req.user, notifies = this.pending[user.id]; + async.eachSeries + res.render('missing_notifies', { - 'name': dbot.config.name, 'user': user.primaryNick, 'notifies': _.sortBy(notifies, 'time') }); @@ -46,10 +73,23 @@ var pages = function(dbot) { }, function(notify) { notifies.push(notify); }, function(err) { - res.render('notifies', { - 'name': dbot.config.name, - 'server': server, - 'notifies': _.sortBy(notifies, 'time') + var pNickCache = {}; + async.eachSeries(notifies, function(notify, next) { + if(!_.has(pNickCache, notify.user)) { + dbot.api.users.getUser(notify.user, function(user) { + pNickCache[notify.user] = user.primaryNick; + notify.user = user.primaryNick; + next(); + }); + } else { + notify.user = pNickCache[notify.user]; + next(); + } + }, function() { + res.render('notifies', { + 'server': server, + 'notifies': _.sortBy(notifies, 'time') + }); }); }); } diff --git a/modules/report/report.js b/modules/report/report.js index 9cc606f..056f6a2 100644 --- a/modules/report/report.js +++ b/modules/report/report.js @@ -139,7 +139,7 @@ var report = function(dbot) { 'id': id, 'server': event.server, 'channel': channelName, - 'user': event.user, + 'user': event.rUser.id, 'time': new Date().getTime(), 'message': message }, function() {});