diff --git a/modules/report/pages.js b/modules/report/pages.js index c199048..a7fb82e 100644 --- a/modules/report/pages.js +++ b/modules/report/pages.js @@ -35,6 +35,21 @@ var pages = function(dbot) { 'notifies': notifies }); }); + }, + + '/report/:server/missing/:user': function(req, res) { + var server = req.params.server, + nick = req.params.user; + + dbot.api.users.resolveUser(server, nick, function(user) { + var notifies = this.pending[user.id]; + console.log(notifies); + res.render('missing_notifies', { + 'name': dbot.config.name, + 'user': nick, + 'notifies': notifies + }); + }.bind(this)); } }; }; diff --git a/modules/report/report.js b/modules/report/report.js index 8c87350..ae4e894 100644 --- a/modules/report/report.js +++ b/modules/report/report.js @@ -28,9 +28,13 @@ var report = function(dbot) { }); }, function() { offlineUsers = perOps; + console.log(offlineUsers); _.each(offlineUsers, function(id) { if(!this.pending[id]) this.pending[id] = []; - this.pending[id].push(message); + this.pending[id].push({ + 'time': new Date().getTime(), + 'message': message + }); }.bind(this)); }.bind(this)); } @@ -50,26 +54,26 @@ var report = function(dbot) { this.listener = function(event) { if(_.has(this.pending, event.rUser.id)) { - var i=0, - pending = this.pending[event.rUser.id]; - - var notifyUser = function(pending) { - if(i >= pending.length) { - delete this.pending[event.rUser.id]; - return; - } - dbot.say(event.server, event.user, pending[i]); - setTimeout(function() { - i++; notifyUser(pending); - }, 5000); - }.bind(this); - - notifyUser(pending); + dbot.say(event.server, event.user, dbot.t('missed_notifies', { + 'user': event.rUser.primaryNick, + 'link': dbot.api.web.getUrl('report/' + event.server + + '/missing/' + event.rUser.primaryNick) + })); } }.bind(this); this.on = 'JOIN'; var commands = { + '~clearmissing': function(event) { + if(_.has(this.pending, event.rUser.id)) { + var count = this.pending[event.rUser.id].length; + delete this.pending[event.rUser.id]; + event.reply(dbot.t('cleared_notifies', { 'count': count })); + } else { + event.reply(dbot.t('no_missed_notifies')); + } + }, + '~report': function(event) { var channelName = event.input[1], nick = event.input[2], diff --git a/modules/report/strings.json b/modules/report/strings.json index 888e9b9..aa2e3ed 100644 --- a/modules/report/strings.json +++ b/modules/report/strings.json @@ -8,6 +8,15 @@ "fr": "Attention : {reporter} a reporté {reported} dans {channel}. Raison donnée : \"{reason}\"", "it": "Attentzone : {reporter} ha segnalato {reported} in {channel}. Motivo : \"{reason}\"" }, + "missed_notifies": { + "en": "{user}, you have some missed notifications (clear these once you have read them using ~clearmissing) - {link}" + }, + "cleared_notifies": { + "en": "{count} pending notifications cleared." + }, + "no_missed_notifies": { + "en": "No missing notifications were available to clear." + }, "reported": { "en": "Thank you, {reported} has been reported to the channel administrators.", "na'vi": "Irayo si ngari, fìtsengìri ayeyktan omum teri {reported}it set.",