File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed
Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments