# HG changeset patch # User Emmanuel Gil Peyrot # Date 1310825454 -7200 # Node ID e32ac29df320fbb3ade64bd1cde8a5d7a51651be # Parent d63a2784564dc1a81046ad0a68cd28a721b13895 Don’t timeout two times. diff --git a/avatar.js b/avatar.js --- a/avatar.js +++ b/avatar.js @@ -109,7 +109,10 @@ var makeError = function(response) { } 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 @@ if (config.useGravatar) 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 @@ function onIq(stanza) { 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 @@ var getVCard = function(jid, res) { .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) {