From f7a5937ed5b9614c8a51e945641dab980cb742ab Mon Sep 17 00:00:00 2001 From: Adriano Rogowski Date: Sun, 10 Mar 2019 17:31:13 -0300 Subject: [PATCH] AXE - chancher lib/super.js to use Rad instead of json plain object. --- lib/super.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/super.js b/lib/super.js index cedd393d..1724f40c 100644 --- a/lib/super.js +++ b/lib/super.js @@ -2,7 +2,7 @@ var Gun = (typeof window !== "undefined")? window.Gun : require('../gun'); var Rad = (Gun.window||{}).Radix || require('./radix'); /// Store the subscribes - Gun.subscribe = {}; /// TODO: use Rad instead of plain object? + Gun.subs = Rad(); function input(msg){ var at = this.as, to = this.to, peer = (msg._||empty).via; var get = msg.get, soul, key; @@ -14,11 +14,20 @@ } else { } - if (!peer.id) {console.log('[WARN] no peer.id %s', soul);} - Gun.subscribe[soul] = Gun.subscribe[soul] || []; - if (Gun.subscribe[soul].indexOf(peer) === -1) { - Gun.subscribe[soul].push(peer); + if (!peer.id) {console.log('[*** WARN] no peer.id %s', soul);} + var subs = Gun.subs(soul) || null; + var tmp = subs ? subs.split(',') : [], p = at.opt.peers; + if (subs) { + Gun.obj.map(subs.split(','), function(peerid) { + if (peerid in p) { tmp.push(peerid); } + }); } + if (tmp.indexOf(peer.id) === -1) { tmp.push(peer.id);} + tmp = tmp.join(','); + Gun.subs(soul, tmp); + var dht = {}; + dht[soul] = tmp; + at.opt.mesh.say({dht:dht}, peer); } to.next(msg); }