# HG changeset patch # User Emmanuel Gil Peyrot # Date 1310825454 -7200 # Node ID e32ac29df320fbb3ade64bd1cde8a5d7a51651be # Parent d63a2784564dc1a81046ad0a68cd28a721b13895 Don’t timeout two times. diff -r d63a2784564d -r e32ac29df320 avatar.js --- a/avatar.js Sat Jul 16 15:29:26 2011 +0200 +++ b/avatar.js Sat Jul 16 16:10:54 2011 +0200 @@ -109,7 +109,10 @@ } if (config.useGravatar) - var noAvatar = function(res, to, message) { + var noAvatar = function(res, to, message, id) { + if (id && sent[id]) + clearTimeout(sent[id].timeout); + var options = { host: 'gravatar.com', port: 80, @@ -152,7 +155,10 @@ return r.end(); }; else - var noAvatar = function(res, to, message) { + var noAvatar = function(res, to, message, id) { + if (id && sent[id]) + clearTimeout(sent[id].timeout); + util.log('No XMPP avatar for ' + to + '.'); return svgError(res, message); }; @@ -170,7 +176,8 @@ if (!sent[id]) return conn.send(makeError(response)); - var res = sent[id]; + clearTimeout(sent[id].timeout); + var res = sent[id].res; delete sent[id]; if (type == 'error') { @@ -245,9 +252,8 @@ .up(); conn.send(toSend); - setTimeout(noAvatar, config.timeout, res, jid, 'Error: XMPP timeout.'); - sent[id] = res; + sent[id] = {res: res, timeout: setTimeout(noAvatar, config.timeout, res, jid, 'Error: XMPP timeout.', id)}; } var showImage = function(jid, res) {