diff options
| author | Ev Bogue <ev@evbogue.com> | 2019-04-08 17:12:30 -0500 | 
|---|---|---|
| committer | Ev Bogue <ev@evbogue.com> | 2019-04-08 17:12:30 -0500 | 
| commit | 4082eaf9abf560c0299780cf50e2583f3185017c (patch) | |
| tree | e9e8780277ecec152b299bdb054afbcc76dba06e | |
| parent | c05445d48c439810820e1c0d5fa5b218ea7dd0c6 (diff) | |
add multipub sync
| -rw-r--r-- | app.js | 64 | ||||
| -rw-r--r-- | lib.js | 8 | 
2 files changed, 68 insertions, 4 deletions
| @@ -19,6 +19,11 @@ if (!localStorage['subscribees']) {    localStorage['subscribees'] = JSON.stringify(subscribees)  } +if (!localStorage['pubs']) { +  var pubs = ['ws://bogbook.com/', 'ws://localhost:8080/'] +  localStorage['pubs'] = JSON.stringify(pubs) +} +  document.body.appendChild(navbar)  function compose (keys, opts) { @@ -87,8 +92,56 @@ function route () {      }, ['Import Key']))      scroller.appendChild(keyMessage) + +    var pubMessage = h('div', {classList: 'message'}) + +    var newPub = h('input', {placeholder: 'Add a new pub. Ex: ws://bogbook.com/'}) + +    var pubs = JSON.parse(localStorage['pubs']) + +    pubMessage.appendChild(h('div', [ +      h('p', {innerHTML: marked('These are your bogbook pubs. These servers will sync data when you publish a new post, when you subscribe to new feeds, and when you click on feed ids.')}), +      newPub, +      h('button', { +        onclick: function () { +          if (newPub.value) { +            pubs.push(newPub.value) +            localStorage['pubs'] = JSON.stringify(pubs)   +            location.reload()  +          } +        } +      }, ['Add Pub']) +    ])) +     +    function removeButton (pubName) { +      var button = h('button', { +        onclick: function () { +          console.log('removing' + pubName) +          for (var i = pubs.length; i--;) { +            if (pubs[i] === pubName) { +              pubs.splice(i, 1); +              localStorage['pubs'] = JSON.stringify(pubs) +              window.location.reload() +            } +          } +        } +      }, ['Remove Pub']) +      return button  +    } + +    for (i = 0; i < pubs.length; i++) { +      var pubName = pubs[i] +      pubMessage.appendChild(h('p', [ +        pubName, +        removeButton(pubName) +      ])) +    }     + +    scroller.appendChild(pubMessage)    } + +    else if (src[0] === '@') {      var profile = h('div', {classList: 'message'})      scroller.appendChild(profile) @@ -171,7 +224,11 @@ function route () {        }      } -    requestFeed(src, 'ws://bogbook.com/')     +    var pubs = JSON.parse(localStorage['pubs']) + +    for (i = 0; i < pubs.length; i++) { +      requestFeed(src, pubs[i])  +    }         if (localStorage[src]) {        var log = JSON.parse(localStorage[src]) @@ -202,7 +259,10 @@ function route () {      console.log(subscribees)      for (i = 0; i < subscribees.length; i++) { -      requestFeed(subscribees[i], 'ws://bogbook.com/') +      var pubs = JSON.parse(localStorage['pubs']) +      for (n = 0; n < pubs.length; n++) { +        requestFeed(subscribees[i], pubs[n]) +      }      }      if (localStorage['log']) { @@ -65,7 +65,6 @@ function requestFeed (src, server) {        var newLog = diff.concat(oldLog)        localStorage['log'] = JSON.stringify(newLog) -        location.reload()      }    } @@ -96,7 +95,12 @@ function publish (content, keys) {    // update the log    updateLog(keys.publicKey, post) -  requestFeed(keys.publicKey, 'ws://bogbook.com/') + +  var pubs = JSON.parse(localStorage['pubs']) + +  for (i = 0; i < pubs.length; i++) { +    requestFeed(keys.publicKey, pubs[i]) +  }    var scroller = document.getElementById('scroller')    if (scroller.firstChild) { | 
