diff options
-rw-r--r-- | gossip.js | 37 | ||||
-rw-r--r-- | server.js | 26 | ||||
-rw-r--r-- | views.js | 2 |
3 files changed, 53 insertions, 12 deletions
@@ -36,6 +36,43 @@ function processreq (req, pubkey, connection, keys) { }) } + if (req.latest) { + var latest + latest = document.getElementById('latest') + var src = window.location.hash.substring(1) + if ((!latest) && (src == req.latest)) { + latest = h('div', {id: 'latest'}) + latest.appendChild(h('div', {classList: 'message', innerHTML: marked('**Still syncing feed**. In the meantime, here are the latest five messages...') + })) + req.feed.forEach(post => { + open(post).then(msg => { + latest.appendChild(render(msg, keys)) + }) + }) + scroller.firstChild.appendChild(latest) + + var timer = setInterval(function () { + localforage.getItem(req.latest).then(feed => { + open(feed[0]).then(msg => { + open(req.feed[0]).then(latestmsg => { + src = window.location.hash.substring(1) + if (msg.seq >= latestmsg.seq) { + latest.parentNode.removeChild(latest) + clearInterval(timer) + console.log('we are caught up, deleting latest div') + } + if (src != req.latest) { + clearInterval(timer) + console.log('we navigated away') + } + }) + }) + }) + console.log('checking to see if we have caught up') + }, 5000) + } + } + if (Array.isArray(req)) { open(req[0]).then(msg => { localforage.getItem(msg.author).then(feed => { @@ -140,17 +140,21 @@ bog.keys().then(key => { } var baserange = feed.length - unboxedreq.seq printClientShorter(msg, req, baserange, endrange) - var latest = JSON.stringify({ - latest: true, - feed: feed.slice(0, 15) - }) - bog.box(latest, req.requester, key).then(boxed => { - var obj = { - requester: key.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) + if (baserange > 50) { + var latest = JSON.stringify({ + latest: unboxedreq.author, + feed: feed.slice(0, 5) + }) + bog.box(latest, req.requester, key).then(boxed => { + var obj = { + requester: key.publicKey, + box: boxed + } + console.log('sending latest ' + unboxedreq.author) + ws.send(JSON.stringify(obj)) + }) + } + var diff = JSON.stringify( feed.slice( endrange, @@ -28,7 +28,7 @@ function profilePage (src, keys) { } sync([src], keys) console.log('syncing ' + src) - }, 2500) + }, 5000) /*timer = function() { if (src === window.location.hash.substring(1)) { |