mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
setTimeout infinity is ackshually instant, so... um, don't
This commit is contained in:
parent
9eac3deb01
commit
e9f2a88e19
@ -2,16 +2,22 @@ module.exports = function(root){ // THIS IS THE UNIVERSAL NOTIFICATION MODULE
|
||||
var to = {}, key = {}, mesh = root.opt.mesh, email = require('./email');
|
||||
if(email.err){ return }
|
||||
mesh.hear['tag'] = function(msg, peer, who){
|
||||
if(who = key[msg.key]){ who.rate = Math.max(msg.rate||1000*60*15, 1000*60); return }
|
||||
if(who = key[msg.key]){
|
||||
if(0 === msg.rate || Infinity == msg.rate){ who.go=0; return }
|
||||
who.rate = Math.max(msg.rate||1000*60*15, 1000*60);
|
||||
return;
|
||||
}
|
||||
if(!msg.src || !msg.email){ return }
|
||||
if(+new Date < peer.emailed + 1000*60*2){ mesh.say({dam:'tag',err:'too fast'},peer); return } // peer can only send notifications > 2min
|
||||
var src; try{ src = new URL(msg.src = msg.src.split(/\s/)[0]); } catch(e){ return } // throws if invalid URL.
|
||||
(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.
|
||||
peer.emailed = +new Date;
|
||||
if(!who.go){ return }
|
||||
mesh.say({dam:'tag',ok:'queued in-memory'},peer);
|
||||
if(who.batch){ return }
|
||||
key[who.key = Math.random().toString(36).slice(2)] = who;
|
||||
who.batch = setTimeout(function(){
|
||||
if(!who.go){ return }
|
||||
email.send({
|
||||
from: process.env.EMAIL,
|
||||
to: msg.email,
|
||||
|
Loading…
x
Reference in New Issue
Block a user