git ssb

0+

Dominic / ssb-ooo



Commit a50da3928500f3ac0fbead0a1b335a3dd5bbc096

get should fallback to ooo if we do not have the massage locally

Dominic Tarr committed on 11/8/2017, 12:44:42 AM
Parent: 01fc1dd4552fcb7a246dc2551b28a35e2b68d7f3

Files changed

index.jschanged
index.jsView
@@ -39,9 +39,9 @@
3939 check: function (key, cb) {
4040 store.keys.get(key, function (err, data) {
4141 if(data) cb(null, data.value)
4242 else
43- sbot.get(key, function (err, msg) {
43 + sbot.get({id:key, raw: true}, function (err, msg) {
4444 cb(null, msg)
4545 })
4646 })
4747 },
@@ -51,8 +51,29 @@
5151 else cb(null, msg)
5252 }
5353 })
5454
55 + function get (id, cb) {
56 + gq.query(id, function (err, msg) {
57 + if(err) return cb(err)
58 + store.add(msg, function (err, data) {
59 + cb(null, data)
60 + })
61 + })
62 + }
63 +
64 + sbot.get.hook(function (fn, args) {
65 + var id = args[0]
66 + var cb = args[1]
67 + if(id.raw) fn(id.id, cb)
68 + else
69 + fn(id, function (err, value) {
70 + console.log("GOT", id, err, value)
71 + if(!err) cb(null, value)
72 + else get(id, cb)
73 + })
74 + })
75 +
5576 sbot.on('rpc:connect', function (rpc, isClient) {
5677 console.log('CONNECT...', id.substring(0, 5), rpc.id.substring(0, 5))
5778 if(isClient) {
5879 var stream = gq.createStream(rpc.id)
@@ -64,15 +85,8 @@
6485 stream: function () {
6586 //called by muxrpc, so remote id is set as this.id
6687 return gq.createStream(this.id)
6788 },
68- get: function (id, cb) {
69- gq.query(id, function (err, msg) {
70- if(err) return cb(err)
71- store.add(msg, function (err, data) {
72- cb(null, data)
73- })
74- })
75- }
89 + get: get
7690 }
7791 }
7892

Built with git-ssb-web