Skip to content

Commit e9f2a88

Browse files
committed
setTimeout infinity is ackshually instant, so... um, don't
1 parent 9eac3de commit e9f2a88

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/tag.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@ module.exports = function(root){ // THIS IS THE UNIVERSAL NOTIFICATION MODULE
22
var to = {}, key = {}, mesh = root.opt.mesh, email = require('./email');
33
if(email.err){ return }
44
mesh.hear['tag'] = function(msg, peer, who){
5-
if(who = key[msg.key]){ who.rate = Math.max(msg.rate||1000*60*15, 1000*60); return }
5+
if(who = key[msg.key]){
6+
if(0 === msg.rate || Infinity == msg.rate){ who.go=0; return }
7+
who.rate = Math.max(msg.rate||1000*60*15, 1000*60);
8+
return;
9+
}
610
if(!msg.src || !msg.email){ return }
711
if(+new Date < peer.emailed + 1000*60*2){ mesh.say({dam:'tag',err:'too fast'},peer); return } // peer can only send notifications > 2min
812
var src; try{ src = new URL(msg.src = msg.src.split(/\s/)[0]); } catch(e){ return } // throws if invalid URL.
913
(who = (to[msg.email] = to[msg.email] || {go:{}})).go[''+src] = 1; // we're keeping in-memory for now, maybe will "stay" to disk in future.
1014
peer.emailed = +new Date;
15+
if(!who.go){ return }
1116
mesh.say({dam:'tag',ok:'queued in-memory'},peer);
1217
if(who.batch){ return }
1318
key[who.key = Math.random().toString(36).slice(2)] = who;
1419
who.batch = setTimeout(function(){
20+
if(!who.go){ return }
1521
email.send({
1622
from: process.env.EMAIL,
1723
to: msg.email,

0 commit comments

Comments
 (0)