diff options
| author | Ev Bogue <ev@evbogue.com> | 2019-04-07 20:02:51 -0500 | 
|---|---|---|
| committer | Ev Bogue <ev@evbogue.com> | 2019-04-07 20:02:51 -0500 | 
| commit | dd8220f7256dd55393d140e70473ae5ce423bb8a (patch) | |
| tree | cc04f0bba1b74617f30fca47b48f2ec3b66297f6 | |
| parent | 6d7db0505da8dc75bc00d872b833b650734ad84c (diff) | |
request subscribed feeds on public feed load
| -rw-r--r-- | app.js | 54 | ||||
| -rw-r--r-- | lib.js | 42 | 
2 files changed, 55 insertions, 41 deletions
| @@ -1,3 +1,6 @@ + + +  var screen = h('div', {id: 'screen'})  document.body.appendChild(screen) @@ -16,7 +19,6 @@ if (!localStorage['subscribees']) {    localStorage['subscribees'] = JSON.stringify(subscribees)  } -  document.body.appendChild(navbar)  function compose (keys, opts) { @@ -169,46 +171,8 @@ function route () {        }      } -    var ws = new WebSocket('ws://bogbook.com/' + src) - -    var clientLog = { -      publicKey: src -    } - -    if (localStorage[src]) { -      clientLog.log = JSON.parse(localStorage[src]) -    } else { -      clientLog.log = [] -    } - -    ws.onopen = function () { -      ws.send(JSON.stringify(clientLog)) -    } - -    ws.onmessage = function (ev) { -      var serverData = JSON.parse(ev.data) -      if (serverData.log.length > clientLog.log.length) { - -        // update the log of the id -        localStorage[src] = JSON.stringify(serverData.log) - -        // contact new items from the log onto the client's log of everything -        var num = serverData.log.length - clientLog.log.length -        var diff = serverData.log.slice(0, num) - -        if (localStorage['log']) { -          var oldLog = JSON.parse(localStorage['log']) -        } else { -          var oldLog = [] -        } - -        var newLog = diff.concat(oldLog) -        localStorage['log'] = JSON.stringify(newLog) - -        location.reload() -      } -    } - +    requestFeed(src, 'ws://bogbook.com/')     +          if (localStorage[src]) {        var log = JSON.parse(localStorage[src])        for (var i=0; i < log.length; i++) { @@ -233,6 +197,14 @@ function route () {    else {      compose(keys) + +    var subscribees = JSON.parse(localStorage['subscribees']) + +    console.log(subscribees) +    for (i = 0; i < subscribees.length; i++) { +      requestFeed(subscribees[i], 'ws://bogbook.com/') +    } +      if (localStorage['log']) {        var log = JSON.parse(localStorage['log'])        for (var i=0; i < log.length; i++) { @@ -29,6 +29,48 @@ function getKeys () {    }  } +function requestFeed (src, server) { +  var ws = new WebSocket(server + src) + +  var clientLog = { +    publicKey: src +  } + +  if (localStorage[src]) { +    clientLog.log = JSON.parse(localStorage[src]) +  } else { +    clientLog.log = [] +  } + +  ws.onopen = function () { +    ws.send(JSON.stringify(clientLog)) +  } + +  ws.onmessage = function (ev) { +    var serverData = JSON.parse(ev.data) +    if (serverData.log.length > clientLog.log.length) { + +      // update the log of the id +      localStorage[src] = JSON.stringify(serverData.log) + +      // contact new items from the log onto the client's log of everything +      var num = serverData.log.length - clientLog.log.length +      var diff = serverData.log.slice(0, num) + +      if (localStorage['log']) { +        var oldLog = JSON.parse(localStorage['log']) +      } else { +        var oldLog = [] +      } + +      var newLog = diff.concat(oldLog) +      localStorage['log'] = JSON.stringify(newLog) + +      location.reload() +    } +  } +} +  // publish new messages to your log  function publish (content, keys) { | 
