Browse Source

send latest five posts if the feed has many unsynced messages, render latest in the client if we are not caught up

master
Ev Bogue 3 years ago
parent
commit
9707770081
  1. 37
      gossip.js
  2. 26
      server.js
  3. 2
      views.js

37
gossip.js

@ -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 => {

26
server.js

@ -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,

2
views.js

@ -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)) {

Loading…
Cancel
Save