diff --git a/sea.js b/sea.js index 65a8cf25..23577623 100644 --- a/sea.js +++ b/sea.js @@ -669,23 +669,30 @@ } // then figuring out all possible candidates having matching username const aliases = [] + let c = 0 // TODO: how about having real chainable map without callback ? Gun.obj.map(rat.put, (at, pub) => { if (!pub.slice || 'pub/' !== pub.slice(0, 4)) { // TODO: ... this would then be .filter((at, pub)) return } + ++c // grab the account associated with this public key. - gunRoot.get(pub).get((at, ev) => { + root.get(pub).get((at, ev) => { pub = pub.slice(4) ev.off() + --c if (at.put){ aliases.push({ pub, at }) } + if (!c && (c = -1)) { + resolve(aliases) + } }) }) - return !aliases.length ? reject({ err: 'Public key does not exist!' }) - : resolve(aliases) + if (!c) { + reject({ err: 'Public key does not exist!' }) + } }) }) module.exports = queryGunAliases