From 58169f4f06879f4e708fcd3ccb0ebfc8eaab9eae Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 20 Oct 2019 10:31:34 -0500 Subject: comment out newer additions that are not quite ready for primetime --- gossip.js | 2 +- render.js | 16 ++++++++-------- server.js | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/gossip.js b/gossip.js index 37a8d90..1c85f88 100644 --- a/gossip.js +++ b/gossip.js @@ -260,7 +260,7 @@ function sync (subs, keys) { } } }) - }, index * 100000) + }, index * 1000) }) }) }) diff --git a/render.js b/render.js index 95fa749..84e7f40 100644 --- a/render.js +++ b/render.js @@ -1,4 +1,4 @@ -function addButton (post, message, keys) { +/*function addButton (post, message, keys) { function readFile () { if (this.files && this.files[0]) { @@ -88,7 +88,7 @@ function addButton (post, message, keys) { }, ['Publish']) ]) - var button = h('button', {/*classList: 'right',*/ + var button = h('button', {classList: 'right', onclick: function () { message.appendChild(h('button', {classList: 'right', onclick: function () { @@ -115,7 +115,7 @@ function addButton (post, message, keys) { return button -} +}*/ function getHeader (post, keys, mini) { @@ -158,7 +158,7 @@ function render (msg, keys, preview) { bog().then(log => { if (log) { log.reverse().forEach(function (nextPost) { - if (nextPost.located == msg.key) { + /*if (nextPost.located == msg.key) { var locatedExists = document.getElementById('located:' + msg.key) var located = h('div', {id: 'located:' + msg.key}, [h('strong', ['Location: ']), nextPost.loc]) if (locatedExists) { @@ -188,7 +188,7 @@ function render (msg, keys, preview) { valuatedExists.parentNode.removeChild(valuatedExists) } message.appendChild(valuated) - } + }*/ if (nextPost.edited == msg.key) { var messageExists = (document.getElementById(nextPost.key) !== null) @@ -294,12 +294,12 @@ function render (msg, keys, preview) { } }, ['Edit'])) } - message.appendChild(addButton(msg, message, keys)) + /*message.appendChild(addButton(msg, message, keys))*/ } } else if (msg.type == 'name') { message.appendChild(getHeader(msg, keys)) message.appendChild(h('span', ['identified ', h('a', {href: '#' + msg.named }, [msg.named.substring(0, 10) + '...']), ' as ' + msg.name])) - } else if (msg.type == 'location') { + } /*else if (msg.type == 'location') { message.appendChild(getHeader(msg, keys)) message.appendChild(h('span', [h('a', {href: '#' + msg.located }, [msg.located.substring(0, 10) + '...']), ' is located: ' + msg.loc])) } else if (msg.type == 'value') { @@ -312,7 +312,7 @@ function render (msg, keys, preview) { var image = h('img', {src: nacl.util.encodeUTF8(openedImg)}) message.appendChild(image) }) - } + }*/ messageDiv.appendChild(message) return messageDiv diff --git a/server.js b/server.js index 6cd0a38..e0b4218 100644 --- a/server.js +++ b/server.js @@ -41,7 +41,7 @@ bog.keys().then(key => { bog.unbox(req.box, req.requester, key).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) //console.log(unboxedreq) - if (unboxedreq.blobFile) { + /*if (unboxedreq.blobFile) { var openedimg = nacl.sign.open(nacl.util.decodeBase64(unboxedreq.blobFile), nacl.util.decodeBase64(unboxedreq.author.substring(1))) if (openedimg) { //console.log(openedimg) @@ -84,7 +84,7 @@ bog.keys().then(key => { }) } } - } + }*/ if (unboxedreq.seq === 0) { console.log(req.requester + ' asked the full log of ' + unboxedreq.author) fs.readFile(bogdir + unboxedreq.author, 'UTF-8', function (err, data) { -- cgit v1.2.3-70-g09d2 From 09baf61106f9e40f6ea444763197997b0e6c08b9 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 16 Nov 2019 16:43:37 -0600 Subject: remove welcome message for now --- app.js | 43 ------------------------------------------- 1 file changed, 43 deletions(-) diff --git a/app.js b/app.js index ed118c8..09b2e5d 100644 --- a/app.js +++ b/app.js @@ -8,49 +8,6 @@ function route (keys) { var screen = document.getElementById('screen') screen.appendChild(scroller) - function nameCheck (id) { - localforage.getItem('name:' + id).then(name => { - if (!name) { - var identify = h('div', {id: 'identify', classList: 'message'}) - scroller.appendChild(identify) - identify.appendChild(h('span', {innerHTML: marked("Hey [" + keys.publicKey.substring(0, 10) + "...](/#"+ keys.publicKey +")! Welcome to Bogbook. If you have any questions be sure to reach out to [@ev](/#@Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0=).")})) - - identify.appendChild(h('span', {innerHTML: marked("Your current public key doesn't have a name yet. Either import your existing id on the [key](/#key) page, or identify yourself using the box below. Identifying is optional, but you'll see this welcome message as long as you don't give yourself a name.")})) - - var input = h('input', {placeholder: 'Give yourself a name'}) - - identify.appendChild(h('div', [ - input, - h('button', { - onclick: function () { - if (input.value) { - content = { - type: 'name', - named: id, - name: input.value - } - publish(content, keys) - setTimeout(function () { - getName(id, keys) - setTimeout(function () { - location.reload() - }, 1000) - }, 1000) - } - } - }, ['Identify']) - ])) - - identify.appendChild(h('span', {innerHTML: marked("Next, make sure to save your public/private keypair on the [key](/#key) page, so that you can continue to use the same identity. No one but you can access your private key, so only you can restore your ability to publish to this identity. If you lose your key, you lose your ability to publish to this identity forever.")})) - - identify.appendChild(h('span', {innerHTML: marked("Finally, be sure to check out the code on [SourceHut](http://git.sr.ht/~ev/bogbook)")})) - - } - }) - } - - nameCheck(keys.publicKey) - if (src === 'key') { keyPage(keys) } else if (src === 'pubs') { -- cgit v1.2.3-70-g09d2 From d7aa96addc75fae89ea33d1259f1c86cb83d5359 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 16 Nov 2019 16:44:32 -0600 Subject: add profile photos that are cropped to 250 by 250 and saved to your log --- bog.js | 35 +++++++++++- css/style.css | 2 + identify.js | 136 +++++++++++++++++++++++++++++++++++++++++++++ index.html | 1 + render.js | 175 +++------------------------------------------------------- views.js | 47 +--------------- 6 files changed, 183 insertions(+), 213 deletions(-) create mode 100644 identify.js diff --git a/bog.js b/bog.js index 6e6df7c..1aff354 100644 --- a/bog.js +++ b/bog.js @@ -96,6 +96,40 @@ async function get (key) { } } +// bog.getImage + +function getImage (id, keys) { + var image = h('img', {classList: 'avatar'}) + + localforage.getItem('image:' + id).then(cache => { + if (cache) { + console.log('GOT IMAGE FROM CACHE: ' + cache) + return image.src = cache + } else { + bog().then(log => { + if (log) { + for (var i = 0; i < log.length; i++) { + if ((log[i].imaged === id) && (log[i].author === keys.publicKey)) { + // if you've identified someone as something else show that something else + localforage.setItem('image:' + id, log[i].image) + console.log('FINDING IMAGE AND SAVING TO CACHE: ' + log[i].image) + image.src = cache + return image.src = cache + } else if ((log[i].imaged === id) && (log[i].author === id)) { + // else if show the image they gave themselves + localforage.setItem('image:' + id, log[i].image) + console.log('FINDING IMAGE AND SAVING TO CACHE: ' + log[i].image) + image.src = cache + return image.src = cache + } + } + } + }) + } + }) + return image +} + // bog.getName -- iterates over a feed and returns a person's name function getName (id, keys) { @@ -129,7 +163,6 @@ function getName (id, keys) { } }) return name - } // bog.regenerate -- regenerates main log by taking all of the feed logs, combinging them, and then sorting them diff --git a/css/style.css b/css/style.css index 08b02ea..4726e84 100644 --- a/css/style.css +++ b/css/style.css @@ -202,6 +202,8 @@ form.search { text-decoration: none; } +.avatar { width: 25px; height: 25px; vertical-align: middle; border-radius: 5px; margin-right: .2em; } + button { display: inline-block; *display: inline; diff --git a/identify.js b/identify.js new file mode 100644 index 0000000..2ba5eea --- /dev/null +++ b/identify.js @@ -0,0 +1,136 @@ +function identify (src, profile, keys) { + + var identifyDiv = h('div') + + if (src != keys.publicKey) { + identifyDiv.appendChild(h('p', ['Please note: ' + src + ' is not you.'])) + } + + var photoURL = {} + + var newPhoto = h('span', [ + h('input', {id: 'input', type: 'file', + onclick: function () { + var canvas = document.getElementById("canvas") + var ctx = canvas.getContext("2d") + + var maxW = 250 + var maxH = 250 + + var input = document.getElementById('input') + input.addEventListener('change', handleFiles) + + function handleFiles(e) { + var img = new Image + img.onload = function() { + var iw = img.width + var ih = img.height + var scale = Math.min((maxW/iw), (maxH/ih)) + var iwScaled = iw*scale + var ihScaled = ih*scale + canvas.width = iwScaled + canvas.height = ihScaled + ctx.drawImage(img, 0, 0, iwScaled, ihScaled) + console.log(canvas.toDataURL('image/jpeg', 0.9)) + photoURL.value = canvas.toDataURL('image/jpeg', 0.9) + //identifyDiv.appendChild(h('img', {src: photoURL.value})) + } + img.src = URL.createObjectURL(e.target.files[0]) + } + } + }), + h('p', ['We recommend uploading a square photo. It will automatically be cropped to 250 x 250 px.']), + h('canvas', {id: 'canvas', width: '0', height: '0'}), + h('button', { + onclick: function () { + identifyDiv.appendChild(identifyButtons) + newPhoto.parentNode.removeChild(newPhoto) + } + }, ['Cancel']), + h('button', { + onclick: function () { + if (photoURL.value) { + content = { + type: 'image', + imaged: src, + image: photoURL.value + } + console.log(content) + localforage.removeItem('image:' + src) + publish(content, keys).then(post => { + open(post).then(msg => { + nameInput.value = '' + scroller.insertBefore(render(msg, keys), scroller.childNodes[1]) + }) + }) + newPhoto.parentNode.removeChild(newPhoto) + identifyDiv.appendChild(identifyButton) + } + } + }, ['Publish']) + ]) + + var nameInput = h('input', {placeholder: 'New name'}) + + var newName = h('div', [ + nameInput, + h('button', { + onclick: function () { + if (nameInput.value) { + content = { + type: 'name', + named: src, + name: nameInput.value + } + localforage.removeItem('name:' + src) + publish(content, keys).then(post => { + open(post).then(msg => { + nameInput.value = '' + scroller.insertBefore(render(msg, keys), scroller.childNodes[1]) + }) + }) + newName.parentNode.removeChild(newName) + identifyDiv.appendChild(identifyButton) + } + } + }, ['Publish']), + h('button', { + onclick: function () { + identifyDiv.appendChild(identifyButtons) + newName.parentNode.removeChild(newName) + } + }, ['Cancel']) + ]) + + var identifyButtons = h('span', [ + h('button', { + onclick: function () { + identifyDiv.appendChild(newName) + identifyButtons.parentNode.removeChild(identifyButtons) + } + }, ['Identify ' + src.substring(0, 10) + '... with a new name']), + h('button', { + onclick: function () { + identifyDiv.appendChild(newPhoto) + identifyButtons.parentNode.removeChild(identifyButtons) + } + }, ['Identify ' + src.substring(0, 10) + '... with a new photo']), + h('button', { + onclick: function () { + identifyDiv.appendChild(identifyButton) + identifyButtons.parentNode.removeChild(identifyButtons) + } + }, ['Cancel']) + ]) + + var identifyButton = h('button', { + onclick: function () { + profile.appendChild(identifyDiv) + profile.appendChild(identifyButtons) + identifyButton.parentNode.removeChild(identifyButton) + } + },['Identify ' + src.substring(0, 10) + '...']) + + return identifyButton +} + diff --git a/index.html b/index.html index a6f0fd9..a663afc 100644 --- a/index.html +++ b/index.html @@ -16,6 +16,7 @@ + diff --git a/render.js b/render.js index 84e7f40..f7031d0 100644 --- a/render.js +++ b/render.js @@ -1,124 +1,4 @@ -/*function addButton (post, message, keys) { - function readFile () { - if (this.files && this.files[0]) { - - var fr = new FileReader() - - fr.addEventListener("load", function(e) { - - var image = e.target.result - var signed = nacl.sign(nacl.util.decodeUTF8(image), nacl.util.decodeBase64(keys.privateKey)) - var signed64 = nacl.util.encodeBase64(signed) - var hash64 = nacl.util.encodeBase64(nacl.hash(signed)) - // we should probably throw out blobs that are too big! - localforage.setItem(hash64, signed64).then(function () { - console.log('saved image to localforage') - var obj = { - type: 'blob', - blobbed: post.key, - hash: hash64 - } - publish(obj, keys).then(published => { - var getPost = document.getElementById(post.key) - open(published).then(opened => { - localforage.getItem(opened.hash).then(signed => { - var openedImg = nacl.sign.open(nacl.util.decodeBase64(signed), nacl.util.decodeBase64(post.author.substring(1))) - console.log(openedImg) - var image = h('img', {src: nacl.util.encodeUTF8(openedImg)}) - getPost.appendChild(image) - message.appendChild(render(published)) - }) - }) - }) - }) - - }) - - fr.readAsDataURL( this.files[0] ) - } - } - - readFile() - - var imageInput = h('span', [ - h('input', {id: 'inp', type:'file'}), - h('img', {id: 'img'}) - ]) - - var locInput = h('input', {placeholder: 'New location'}) - var locDiv = h('div', [ - locInput, - h('button', { - onclick: function () { - var obj = { - type: 'location', - located: post.key, - loc: locInput.value - } - publish(obj, keys).then(published => { - open(published).then(opened => { - message.parentNode.appendChild(h('div', {classList: 'submessage'}, [render(opened, keys)])) - locDiv.parentNode.removeChild(locDiv) - }) - }) - } - }, ['Publish']) - ]) - - var valueInput = h('input', {placeholder: '0.00'}) - var currencyInput = h('input', {placeholder: 'Currency'}) - var valueDiv = h('div', [ - valueInput, - currencyInput, - h('button', { - onclick: function () { - var obj = { - type: 'value', - value: valueInput.value, - valuated: post.key, - currency: currencyInput.value - } - publish(obj, keys).then(published => { - open(published).then(opened => { - message.parentNode.appendChild(h('div', {classList: 'submessage'}, [render(opened, keys)])) - valueDiv.parentNode.removeChild(valueDiv) - }) - }) - } - }, ['Publish']) - ]) - - var button = h('button', {classList: 'right', - onclick: function () { - message.appendChild(h('button', {classList: 'right', - onclick: function () { - message.appendChild(locDiv) - } - }, ['Location'])) - - message.appendChild(h('button', {classList: 'right', - onclick: function () { - message.appendChild(imageInput) - document.getElementById("inp").addEventListener("change", readFile); - } - }, ['Image'])) - - message.appendChild(h('button', {classList: 'right', - onclick: function () { - message.appendChild(valueDiv) - } - }, ['Value'])) - } - - }, ['Add']) - - - - return button -}*/ - function getHeader (post, keys, mini) { - var getRaw = h('button', { onclick: function () { var raw = h('pre', [h('code', [JSON.stringify(post)])]) @@ -143,6 +23,7 @@ function getHeader (post, keys, mini) { ]), h('p', [ h('a', {href: '#' + post.author}, [ + getImage(post.author, keys), getName(post.author, keys) ]), mini @@ -158,38 +39,6 @@ function render (msg, keys, preview) { bog().then(log => { if (log) { log.reverse().forEach(function (nextPost) { - /*if (nextPost.located == msg.key) { - var locatedExists = document.getElementById('located:' + msg.key) - var located = h('div', {id: 'located:' + msg.key}, [h('strong', ['Location: ']), nextPost.loc]) - if (locatedExists) { - locatedExists.parentNode.removeChild(locatedExists) - } - message.appendChild(located) - } - - if (nextPost.blobbed == msg.key) { - localforage.getItem(nextPost.hash).then(signed => { - if (signed) { - var openedImg = nacl.sign.open(nacl.util.decodeBase64(signed), nacl.util.decodeBase64(nextPost.author.substring(1))) - var image = h('img', {src: nacl.util.encodeUTF8(openedImg)}) - blobSync(nextPost.hash, nextPost.author, keys, false ) - message.appendChild(image) - } else { - console.log('we don\'t have the blob') - blobSync(nextPost.hash, nextPost.author, keys, true ) - } - }) - } - - if (nextPost.valuated == msg.key) { - var valuatedExists = document.getElementById('valuated:' + msg.key) - var valuated = h('div', {id: 'valuated:' + msg.key}, [h('strong', ['Price: ' ]), nextPost.value + ' ' + nextPost.currency]) - if (valuatedExists) { - valuatedExists.parentNode.removeChild(valuatedExists) - } - message.appendChild(valuated) - }*/ - if (nextPost.edited == msg.key) { var messageExists = (document.getElementById(nextPost.key) !== null) var msgcontents = document.getElementById('content:' + msg.key) @@ -294,25 +143,19 @@ function render (msg, keys, preview) { } }, ['Edit'])) } - /*message.appendChild(addButton(msg, message, keys))*/ } } else if (msg.type == 'name') { message.appendChild(getHeader(msg, keys)) message.appendChild(h('span', ['identified ', h('a', {href: '#' + msg.named }, [msg.named.substring(0, 10) + '...']), ' as ' + msg.name])) - } /*else if (msg.type == 'location') { + } else if (msg.type == 'image') { message.appendChild(getHeader(msg, keys)) - message.appendChild(h('span', [h('a', {href: '#' + msg.located }, [msg.located.substring(0, 10) + '...']), ' is located: ' + msg.loc])) - } else if (msg.type == 'value') { - message.appendChild(getHeader(msg, keys)) - message.appendChild(h('span', [h('a', {href: '#' + msg.valuated}, [msg.valuated.substring(0, 10) + '...']), ' is worth: ' + msg.value + ' ' + msg.currency])) - } else if (msg.type == 'blob') { - message.appendChild(getHeader(msg, keys)) - localforage.getItem(msg.hash).then(signed => { - var openedImg = nacl.sign.open(nacl.util.decodeBase64(signed), nacl.util.decodeBase64(msg.author.substring(1))) - var image = h('img', {src: nacl.util.encodeUTF8(openedImg)}) - message.appendChild(image) - }) - }*/ + message.appendChild(h('span', [ + 'identified ', + h('a', { href: '#' + msg.imaged }, [msg.imaged.substring(0, 10) + '...']), + ' as ', + h('img', {src: msg.image}) + ])) + } messageDiv.appendChild(message) return messageDiv diff --git a/views.js b/views.js index 87a4c10..0d8a532 100644 --- a/views.js +++ b/views.js @@ -10,7 +10,6 @@ function profilePage (src, keys) { scroller.appendChild(profile) - if (src != keys.publicKey) { reply = { author: src } scroller.appendChild(composer(keys, reply)) @@ -22,49 +21,16 @@ function profilePage (src, keys) { sync(subs, keys) - var input = h('input', {placeholder: 'New name'}) - profile.appendChild(h('a', {href: '#' + src}, [getName(src, keys)])) - profile.appendChild(h('br')) - var identify = h('div', [ - input, - h('button', { - onclick: function () { - if (input.value) { - content = { - type: 'name', - named: src, - name: input.value - } - localforage.removeItem('name:' + src) - publish(content, keys).then(post => { - open(post).then(msg => { - input.value = '' - scroller.insertBefore(render(msg, keys), scroller.childNodes[1]) - }) - }) - } - } - }, ['Identify']) - ]) - - var identifyButton = h('button', { - onclick: function () { - profile.appendChild(identify) - identifyButton.parentNode.removeChild(identifyButton) - } - }, ['Identify ' + src.substring(0, 10) + '...']) - var mentionsButton = h('button', { onclick: function () { location.href = '#?' + src } }, ['Mentions']) - profile.appendChild(identifyButton) - + profile.appendChild(identify(src, profile, keys)) profile.appendChild(mentionsButton) localforage.getItem('subscriptions').then(function (subs) { @@ -103,22 +69,11 @@ function profilePage (src, keys) { }) } }) - - /*bog(src).then(log => { - if (log) { - log.forEach(function (msg) { - open(msg).then(post => { - scroller.appendChild(render(post, keys)) - }) - }) - } - })*/ } function searchPage (src, keys) { var search = src.substring(1).replace("%20"," ").toUpperCase() - //scroller.appendChild(composer(keys)) bog().then(log => { if (log) { log.forEach(function (msg) { -- cgit v1.2.3-70-g09d2 From db7b5eb235a80db1c41765a097830c36e4ffa9bb Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 17 Nov 2019 09:08:42 -0600 Subject: pass different image classes to getImage --- bog.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bog.js b/bog.js index 1aff354..a9e2cd3 100644 --- a/bog.js +++ b/bog.js @@ -98,8 +98,12 @@ async function get (key) { // bog.getImage -function getImage (id, keys) { - var image = h('img', {classList: 'avatar'}) +function getImage (id, keys, classList) { + if (classList) { + var image = h('img', {classList: classList}) + } else { + var image = h('img', {classList: 'avatar'}) + } localforage.getItem('image:' + id).then(cache => { if (cache) { -- cgit v1.2.3-70-g09d2 From e555c43e71c2d86ee86e40c3a756f6ac87c480b2 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 17 Nov 2019 09:08:59 -0600 Subject: show profile photo on profile, misc style tweaks --- css/style.css | 1 + render.js | 14 +++++++------- views.js | 6 +++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/css/style.css b/css/style.css index 4726e84..fad1090 100644 --- a/css/style.css +++ b/css/style.css @@ -202,6 +202,7 @@ form.search { text-decoration: none; } +.profileAvatar { width: 75px; vertical-align: top; border-radius: 5px; margin-right: .25em; margin-bottom: .25em;} .avatar { width: 25px; height: 25px; vertical-align: middle; border-radius: 5px; margin-right: .2em; } button { diff --git a/render.js b/render.js index f7031d0..8ed5cba 100644 --- a/render.js +++ b/render.js @@ -145,16 +145,16 @@ function render (msg, keys, preview) { } } } else if (msg.type == 'name') { - message.appendChild(getHeader(msg, keys)) - message.appendChild(h('span', ['identified ', h('a', {href: '#' + msg.named }, [msg.named.substring(0, 10) + '...']), ' as ' + msg.name])) + var mini = h('span', [' identified ', h('a', {href: '#' + msg.named }, [msg.named.substring(0, 10) + '...']), ' as ' + msg.name]) + message.appendChild(getHeader(msg, keys, mini)) } else if (msg.type == 'image') { - message.appendChild(getHeader(msg, keys)) - message.appendChild(h('span', [ - 'identified ', + var mini = h('span', [ + ' identified ', h('a', { href: '#' + msg.imaged }, [msg.imaged.substring(0, 10) + '...']), ' as ', - h('img', {src: msg.image}) - ])) + h('img', {src: msg.image, classList: 'avatar'}) + ]) + message.appendChild(getHeader(msg, keys, mini)) } messageDiv.appendChild(message) diff --git a/views.js b/views.js index 0d8a532..018802d 100644 --- a/views.js +++ b/views.js @@ -21,7 +21,11 @@ function profilePage (src, keys) { sync(subs, keys) - profile.appendChild(h('a', {href: '#' + src}, [getName(src, keys)])) + profile.appendChild(h('a', {href: '#' + src}, [ + getImage(src, keys, 'profileAvatar'), + getName(src, keys) + ])) + profile.appendChild(h('br')) var mentionsButton = h('button', { -- cgit v1.2.3-70-g09d2 From 8e4ebcffefb4c5b27020699418391572126c96a0 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 17 Nov 2019 10:22:14 -0600 Subject: add a reply button to profile pages --- views.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/views.js b/views.js index 018802d..9e0195c 100644 --- a/views.js +++ b/views.js @@ -5,17 +5,14 @@ function threadPage (src, keys) { } function profilePage (src, keys) { + var gotName = getName(src, keys) + var msg = {} + msg.author = src var profile = h('div', {classList: 'profile'}) scroller.appendChild(profile) - if (src != keys.publicKey) { - reply = { author: src } - scroller.appendChild(composer(keys, reply)) - } else { - scroller.appendChild(composer(keys)) - } var subs = [src] @@ -34,9 +31,17 @@ function profilePage (src, keys) { } }, ['Mentions']) + var respond = h('button', { + onclick: function () { + scroller.insertBefore(composer(keys, msg, gotName), scroller.childNodes[1]) + } + }, ['Reply to ' + gotName.textContent]) + profile.appendChild(identify(src, profile, keys)) profile.appendChild(mentionsButton) + profile.appendChild(respond) + localforage.getItem('subscriptions').then(function (subs) { if (subs.includes(src)) { profile.appendChild(h('button', { -- cgit v1.2.3-70-g09d2 From a83eb1a62d8c928414edaff6a4ef3a383b677bd3 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 17 Nov 2019 12:23:05 -0600 Subject: remove unused code --- gossip.js | 83 --------------------------------------------------------------- server.js | 65 +------------------------------------------------ 2 files changed, 1 insertion(+), 147 deletions(-) diff --git a/gossip.js b/gossip.js index 1c85f88..00e6f40 100644 --- a/gossip.js +++ b/gossip.js @@ -1,86 +1,3 @@ -function blobSync (blob, author, keys, needs) { - console.log(needs) - - var wsServers - - // duplicate code, we should abstract this - localforage.getItem('securepubs').then(function (servers) { - if (servers) { - wsServers = servers - } else { - servers = ['ws://bogbook.com', 'ws://localhost:8080'] - var pubs = [] - servers.forEach(server => { - var ws = new WebSocket(server) - ws.onopen = function () { - ws.send(JSON.stringify({requester: keys.publicKey, sendpub: true})) - } - ws.onmessage = function (message) { - pubs.push(server + '/~' + message.data) - localforage.setItem('securepubs', pubs) - } - }) - wsServers = pubs - } - }).then(function () { - wsServers.forEach(function (server, index) { - setTimeout(function () { - var split = server.split('~') - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) - - console.log('requesting ' + blob + ' from ' + server) - ws.onopen = function () { - var req = { - blob: blob, - needs: needs - } - - box(JSON.stringify(req), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - ws.onmessage = function (message) { - var serverreq = JSON.parse(message.data) - unbox(serverreq.box, serverreq.requester, keys).then(unboxed => { - - var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - //console.log(unboxedreq) - if (unboxedreq.blobFile) { - var openedimg = nacl.sign.open(nacl.util.decodeBase64(unboxedreq.blobFile), nacl.util.decodeBase64(author.substring(1))) - if (openedimg) { - localforage.setItem(unboxedreq.blob, unboxedreq.blobFile) - } - } else { - localforage.getItem(unboxedreq.blob).then(blob => { - if (blob) { - var nextreq = { - author: author, - blob: unboxedreq.blob, - blobFile: blob - } - box(JSON.stringify(nextreq), serverreq.requester, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - }) - } - }) - } - }, index * 10000) - }) - }) -} - function sync (subs, keys) { var wsServers diff --git a/server.js b/server.js index e0b4218..c278a3a 100644 --- a/server.js +++ b/server.js @@ -36,72 +36,9 @@ bog.keys().then(key => { var req = JSON.parse(message) if (req.sendpub) { ws.send(key.publicKey) - } - else { + } else { bog.unbox(req.box, req.requester, key).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - //console.log(unboxedreq) - /*if (unboxedreq.blobFile) { - var openedimg = nacl.sign.open(nacl.util.decodeBase64(unboxedreq.blobFile), nacl.util.decodeBase64(unboxedreq.author.substring(1))) - if (openedimg) { - //console.log(openedimg) - fs.writeFileSync(blobdir + '/' + sanitize(unboxedreq.blob), unboxedreq.blobFile, 'UTF-8') - console.log('received blob ' + unboxedreq.blob + ' from ' + req.requester + ' and saved to blobs folder') - } - } - if (unboxedreq.blob) { - console.log(req.requester + ' has requested the blob ' + unboxedreq.blob) - var blobExists = fs.existsSync(blobdir + '/' + sanitize(unboxedreq.blob)) - if (unboxedreq.needs) { - console.log(req.requester + ' needs ' + unboxedreq.blob + ' do we have it?') - if (blobExists) { - console.log('We have it, so send it to the client') - var blobToSend = fs.readFileSync(blobdir + '/' + sanitize(unboxedreq.blob), 'UTF-8') - var sendblob = { - blob: unboxedreq.blob, - blobFile: blobToSend - } - console.log(sendblob) - bog.box(JSON.stringify(sendblob), req.requester, key).then(boxed => { - var obj = { - requester: key.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - } else { - console.log(req.requester + ' has ' + unboxedreq.blob + ' do we need it?') - if (!blobExists) { - console.log('We need it, so request it from the client') - var blobreq = { blob: unboxedreq.blob, needs: true } - bog.box(JSON.stringify(blobreq), req.requester, key).then(boxed => { - var obj = { - requester: key.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - } - }*/ - if (unboxedreq.seq === 0) { - console.log(req.requester + ' asked the full log of ' + unboxedreq.author) - fs.readFile(bogdir + unboxedreq.author, 'UTF-8', function (err, data) { - if (data) { - //var feed = JSON.stringify(data) - var feed = data - bog.box(feed, req.requester, key).then(boxed => { - var obj = { - requester: key.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - console.log('Sent full log of ' + unboxedreq.author + ' to ' + req.requester) - }) - } - }) - } if (unboxedreq.seq) { console.log(req.requester + ' asked for feed ' + unboxedreq.author + ' after sequence ' + unboxedreq.seq) // check to see if we have the feed on disk -- cgit v1.2.3-70-g09d2 From 2a2f53df4c4e007ec4864c31df806c9b653c063d Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 22 Nov 2019 10:49:27 -0600 Subject: remove console logs --- bog.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/bog.js b/bog.js index a9e2cd3..2ce37bb 100644 --- a/bog.js +++ b/bog.js @@ -107,7 +107,6 @@ function getImage (id, keys, classList) { localforage.getItem('image:' + id).then(cache => { if (cache) { - console.log('GOT IMAGE FROM CACHE: ' + cache) return image.src = cache } else { bog().then(log => { @@ -116,13 +115,11 @@ function getImage (id, keys, classList) { if ((log[i].imaged === id) && (log[i].author === keys.publicKey)) { // if you've identified someone as something else show that something else localforage.setItem('image:' + id, log[i].image) - console.log('FINDING IMAGE AND SAVING TO CACHE: ' + log[i].image) image.src = cache return image.src = cache } else if ((log[i].imaged === id) && (log[i].author === id)) { // else if show the image they gave themselves localforage.setItem('image:' + id, log[i].image) - console.log('FINDING IMAGE AND SAVING TO CACHE: ' + log[i].image) image.src = cache return image.src = cache } @@ -143,7 +140,6 @@ function getName (id, keys) { localforage.getItem('name:' + id).then(cache => { if (cache) { - console.log('GOT NAME FROM CACHE: ' + cache) return name.textContent = '@' + cache } else { bog().then(log => { @@ -152,12 +148,10 @@ function getName (id, keys) { if ((log[i].named === id) && (log[i].author === keys.publicKey)) { // if you've identified someone as something else show that something else localforage.setItem('name:' + id, log[i].name) - console.log('FINDING NAME AND SAVING TO CACHE: ' + log[i].name) return name.textContent = '@' + log[i].name } else if ((log[i].named === id) && (log[i].author === id)) { // else if show the name they gave themselves localforage.setItem('name:' + id, log[i].name) - console.log('FINDING NAME AND SAVING TO CACHE: ' + log[i].name) return name.textContent = '@' + log[i].name } // there should probably be some sort of sybil attack resiliance here (weight avatar name based on number of times used by individuals), but this will do for now. -- cgit v1.2.3-70-g09d2 From 6f73dcee4fbf3935a411c7a5434779ff1935d342 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 22 Nov 2019 10:49:39 -0600 Subject: remove console logs --- gossip.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/gossip.js b/gossip.js index 00e6f40..f7ed484 100644 --- a/gossip.js +++ b/gossip.js @@ -46,10 +46,8 @@ function sync (subs, keys) { } ws.onmessage = function (message) { var req = JSON.parse(message.data) - console.log(req) unbox(req.box, req.requester, keys).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - console.log(unboxedreq) if (unboxedreq.seq === 0) { var stringedfeed = JSON.stringify(srclog) box(stringedfeed, serverpub, keys).then(boxed => { @@ -58,7 +56,6 @@ function sync (subs, keys) { box: boxed } console.log('Sending entire log of ' + msg.author + ' to ' + serverpub) - console.log(obj) ws.send(JSON.stringify(obj)) }) } -- cgit v1.2.3-70-g09d2 From 2a8e4ab57aa420727b439f983d8a37d729a2c893 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 22 Nov 2019 10:50:47 -0600 Subject: bogbook @ 1.6.0 -- real-time bogbook and only send 25 posts at a time --- package-lock.json | 26 +++++++++++++------------- package.json | 2 +- server.js | 21 +++++++++++++++------ views.js | 33 +++++++++++++++++++++++++++++---- 4 files changed, 58 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 799f9d0..1571dd4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,13 @@ { "name": "bogbook", - "version": "1.5.0", + "version": "1.6.0", "lockfileVersion": 1, "requires": true, "dependencies": { "async-limiter": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", - "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==" + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", + "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" }, "charset": { "version": "1.0.1", @@ -58,9 +58,9 @@ "integrity": "sha1-HxbkqiKwTRM2tmGIpmrzxgDDpm0=" }, "mime": { - "version": "2.4.3", - "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.3.tgz", - "integrity": "sha512-QgrPRJfE+riq5TPZMcHZOtm8c6K/yYrMbKIoRfapfiGLxS8OTeIfRhUGW5LU7MlRa52KOAGCfUNruqLrIBvWZw==" + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz", + "integrity": "sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA==" }, "minimist": { "version": "1.2.0", @@ -76,9 +76,9 @@ } }, "open": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/open/-/open-6.2.0.tgz", - "integrity": "sha512-Vxf6HJkwrqmvh9UAID3MnMYXntbTxKLOSfOnO7LJdzPf3NE3KQYFNV0/Lcz2VAndbRFil58XVCyh8tiX11fiYw==", + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/open/-/open-6.4.0.tgz", + "integrity": "sha512-IFenVPgF70fSm1keSd2iDBIDIBZkroLeuffXq+wKTzTJlBpesFWojV9lb8mzOfaAzM1sr7HQHuO0vtV0zYekGg==", "requires": { "is-wsl": "^1.1.0" } @@ -110,9 +110,9 @@ "integrity": "sha1-RXbBzuXi1j0gf+5S8boCgZSAvHU=" }, "url-join": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.0.tgz", - "integrity": "sha1-TTNA6AfTdzvamZH4MFrNzCpmXSo=" + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", + "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==" }, "utf8-byte-length": { "version": "1.0.4", diff --git a/package.json b/package.json index 5632bad..3386ed5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bogbook", - "version": "1.5.0", + "version": "1.6.0", "description": "secure blockchain logging (blogging, without the l) -- bogging", "main": "server.js", "scripts": { diff --git a/server.js b/server.js index c278a3a..e2b2f06 100644 --- a/server.js +++ b/server.js @@ -39,12 +39,10 @@ bog.keys().then(key => { } else { bog.unbox(req.box, req.requester, key).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - if (unboxedreq.seq) { + if (unboxedreq.seq >= 0) { console.log(req.requester + ' asked for feed ' + unboxedreq.author + ' after sequence ' + unboxedreq.seq) - // check to see if we have the feed on disk fs.readFile(bogdir + unboxedreq.author, 'UTF-8', function (err, data) { if (data) { - // TODO open the latest message, and check the sequence number var feed = JSON.parse(data) bog.open(feed[0]).then(msg => { if (unboxedreq.seq === msg.seq) { @@ -63,10 +61,21 @@ bog.keys().then(key => { ws.send(JSON.stringify(obj)) }) } - + if (unboxedreq.seq < msg.seq) { - console.log('client feed is shorter, sending diff to client') - var diff = JSON.stringify(feed.slice(0, msg.seq - unboxedreq.seq)) + var endrange = feed.length - unboxedreq.seq - 25 + if (endrange < 0) { + endrange = feed.length - unboxedreq.seq - 1 + } + var baserange = feed.length - unboxedreq.seq + + console.log('client feed is shorter, sending from ' + baserange + ' to ' + endrange + ' to client') + var diff = JSON.stringify( + feed.slice( + endrange, + baserange) + ) + //var diff = JSON.stringify(feed.slice(0, msg.seq - unboxedreq.seq)) bog.box(diff, req.requester, key).then(boxed => { var obj = { requester: key.publicKey, diff --git a/views.js b/views.js index 9e0195c..5fd4f31 100644 --- a/views.js +++ b/views.js @@ -12,11 +12,20 @@ function profilePage (src, keys) { var profile = h('div', {classList: 'profile'}) scroller.appendChild(profile) - + scroller.appendChild(h('div')) var subs = [src] - sync(subs, keys) + var interval = 1000 + timer = function() { + if (src === window.location.hash.substring(1)) { + if (interval < 10000) { interval = interval + 200 } + sync(subs, keys) + setTimeout(timer, interval) + } + } + timer() + profile.appendChild(h('a', {href: '#' + src}, [ getImage(src, keys, 'profileAvatar'), @@ -100,11 +109,27 @@ function publicPage (keys) { localforage.getItem('subscriptions').then(function (subs) { if (subs) { - sync(subs, keys) + var interval = 1000 + timer = function() { + if ('' === window.location.hash.substring(1)) { + if (interval < 10000) { interval = interval + 1000 } + sync(subs, keys) + setTimeout(timer, interval) + } + } + timer() } else { var subs = [keys.publicKey] localforage.setItem('subscriptions', subs) - sync(subs, keys) + var interval = 1000 + timer = function() { + if ('' === window.location.hash.substring(1)) { + if (interval < 10000) { interval = interval + 1000 } + sync(subs, keys) + setTimeout(timer, interval) + } + } + timer() } }) -- cgit v1.2.3-70-g09d2 From 5b4deca9a50c4bdc880eb8d6649e9ab74d759fd8 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 22 Nov 2019 12:37:02 -0600 Subject: make it so you sync yourself without having to subscribe to yourself, remove subscribe button from own view --- views.js | 69 ++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/views.js b/views.js index 5fd4f31..fcab7dc 100644 --- a/views.js +++ b/views.js @@ -48,27 +48,28 @@ function profilePage (src, keys) { profile.appendChild(identify(src, profile, keys)) profile.appendChild(mentionsButton) - profile.appendChild(respond) - localforage.getItem('subscriptions').then(function (subs) { - if (subs.includes(src)) { - profile.appendChild(h('button', { - onclick: function () { - subs = subs.filter(a => a !== src) - localforage.setItem('subscriptions', subs).then(function () { location.reload() }) - } - }, ['Unsubscribe'])) - } else { - profile.appendChild(h('button', { - onclick: function () { - subs.push(src) - localforage.setItem('subscriptions', subs).then(function () { location.reload() }) - } - }, ['Subscribe'])) - } - }) - + if (src != keys.publicKey) { + localforage.getItem('subscriptions').then(function (subs) { + if (subs.includes(src)) { + profile.appendChild(h('button', { + onclick: function () { + subs = subs.filter(a => a !== src) + localforage.setItem('subscriptions', subs).then(function () { location.reload() }) + } + }, ['Unsubscribe'])) + } else { + profile.appendChild(h('button', { + onclick: function () { + subs.push(src) + localforage.setItem('subscriptions', subs).then(function () { location.reload() }) + } + }, ['Subscribe'])) + } + }) + } + profile.appendChild(h('button', { onclick: function () { localforage.removeItem(src).then(function () { @@ -106,29 +107,23 @@ function searchPage (src, keys) { } function publicPage (keys) { - localforage.getItem('subscriptions').then(function (subs) { - if (subs) { - var interval = 1000 - timer = function() { - if ('' === window.location.hash.substring(1)) { - if (interval < 10000) { interval = interval + 1000 } - sync(subs, keys) - setTimeout(timer, interval) - } + var interval = 1000 + timer = function() { + if ('' === window.location.hash.substring(1)) { + if (interval < 10000) { interval = interval + 1000 } + sync(subs, keys) + setTimeout(timer, interval) } + } + + if (subs) { + subs.push(keys.publicKey) timer() } else { - var subs = [keys.publicKey] + var subs = [] localforage.setItem('subscriptions', subs) - var interval = 1000 - timer = function() { - if ('' === window.location.hash.substring(1)) { - if (interval < 10000) { interval = interval + 1000 } - sync(subs, keys) - setTimeout(timer, interval) - } - } + subs.push(keys.publicKey) timer() } }) -- cgit v1.2.3-70-g09d2 From 1ab6891e89c18fc5cfcd1f7582e85ff9d3725b75 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 23 Nov 2019 10:06:03 -0600 Subject: load only 25 posts at a time into the DOM --- views.js | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/views.js b/views.js index fcab7dc..521de8d 100644 --- a/views.js +++ b/views.js @@ -79,11 +79,25 @@ function profilePage (src, keys) { } }, ['Delete feed'])) + async function addPosts (posts, keys) { + posts.forEach(function (msg) { + if (msg.author === src) { + scroller.appendChild(render(msg, keys)) + } + }) + } bog().then(log => { + var index = 0 if (log) { - log.forEach(function (msg) { - if (msg.author === src) { - scroller.appendChild(render(msg, keys)) + var posts = log.slice(index, index + 25) + addPosts(posts, keys).then(done => { + window.onscroll = function(ev) { + if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) { + posts = log.slice(index, index + 25) + index = index + 25 + addPosts(posts, keys) + console.log("Bottom of page"); + } } }) } @@ -145,10 +159,26 @@ function publicPage (keys) { scroller.appendChild(div) scroller.appendChild(composer(keys)) + + async function addPosts (posts, keys) { + posts.forEach(function (msg) { + scroller.appendChild(render(msg, keys)) + }) + } + bog().then(log => { + var index = 0 if (log) { - log.forEach(function (msg) { - scroller.appendChild(render(msg, keys)) + var posts = log.slice(index, index + 25) + addPosts(posts, keys).then(done => { + window.onscroll = function(ev) { + if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) { + posts = log.slice(index, index + 25) + index = index + 25 + addPosts(posts, keys) + console.log("Bottom of page"); + } + } }) } }) -- cgit v1.2.3-70-g09d2 From 40738076eedb3ba864d3188e66d00df830575c59 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 23 Nov 2019 10:11:41 -0600 Subject: whoops did not iterate index right --- views.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/views.js b/views.js index 521de8d..854c7ba 100644 --- a/views.js +++ b/views.js @@ -91,6 +91,7 @@ function profilePage (src, keys) { if (log) { var posts = log.slice(index, index + 25) addPosts(posts, keys).then(done => { + index = index + 25 window.onscroll = function(ev) { if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) { posts = log.slice(index, index + 25) @@ -171,6 +172,7 @@ function publicPage (keys) { if (log) { var posts = log.slice(index, index + 25) addPosts(posts, keys).then(done => { + index = index + 25 window.onscroll = function(ev) { if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) { posts = log.slice(index, index + 25) -- cgit v1.2.3-70-g09d2 From 0eb66af71c4e1ad3bad82aabc560c69835f2c48c Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 23 Nov 2019 10:17:12 -0600 Subject: I think this fixes a rendering artifact --- views.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/views.js b/views.js index 854c7ba..333db18 100644 --- a/views.js +++ b/views.js @@ -26,7 +26,6 @@ function profilePage (src, keys) { } timer() - profile.appendChild(h('a', {href: '#' + src}, [ getImage(src, keys, 'profileAvatar'), getName(src, keys) @@ -96,7 +95,9 @@ function profilePage (src, keys) { if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) { posts = log.slice(index, index + 25) index = index + 25 - addPosts(posts, keys) + if (src === window.location.hash.substring(1)) { + addPosts(posts, keys) + } console.log("Bottom of page"); } } @@ -177,7 +178,9 @@ function publicPage (keys) { if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) { posts = log.slice(index, index + 25) index = index + 25 - addPosts(posts, keys) + if ('' === window.location.hash.substring(1)) { + addPosts(posts, keys) + } console.log("Bottom of page"); } } -- cgit v1.2.3-70-g09d2 From 7a03c9794381baba8f8e61be6d8c919907dcf641 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 23 Nov 2019 14:00:31 -0600 Subject: add a quickName function that only looks at cached name --- bog.js | 13 +++++++++++-- composer.js | 2 +- render.js | 51 ++++++++++++++++++++++++++------------------------- views.js | 15 +++++++++------ 4 files changed, 47 insertions(+), 34 deletions(-) diff --git a/bog.js b/bog.js index 2ce37bb..49d0b52 100644 --- a/bog.js +++ b/bog.js @@ -81,7 +81,6 @@ async function unbox (boxed, sender, keys) { return message } - // bog.get -- iterates over log and returns a post. // EX: get('%x5T7KZ5haR2F59ynUuCggwEdFXlLHEtFoBQIyKYppZYerq9oMoIqH76YzXQpw2DnYiM0ugEjePXv61g3E4l/Gw==').then(msg => { console.log(msg)}) @@ -140,6 +139,7 @@ function getName (id, keys) { localforage.getItem('name:' + id).then(cache => { if (cache) { + console.log(cache) return name.textContent = '@' + cache } else { bog().then(log => { @@ -163,6 +163,16 @@ function getName (id, keys) { return name } +async function quickName (id, keys) { + var cache = await localforage.getItem('name:' + id) + + if (cache) { + return '@' + cache + } else { + return id.substring(0, 10) + } +} + // bog.regenerate -- regenerates main log by taking all of the feed logs, combinging them, and then sorting them function regenerate (home) { @@ -201,7 +211,6 @@ function regenerate (home) { // EX: bog().then(log => { console.log(log)}) // EX: bog('@ExE3QXmBhYQlGVA3WM2BD851turNzwhruWbIpMd7rbQ=').then(log => { console.log(log)}) - async function bog (feed) { if (feed) { var log = await localforage.getItem(feed) diff --git a/composer.js b/composer.js index c7773d4..b44b773 100644 --- a/composer.js +++ b/composer.js @@ -6,7 +6,7 @@ function composer (keys, reply, gotName, edit) { console.log(reply) var textarea = h('textarea', [reply.text]) } else if (gotName) { - var textarea = h('textarea', ['[' + gotName.textContent + '](' + reply.author + ')']) + var textarea = h('textarea', ['[' + gotName + '](' + reply.author + ')']) } else { var textarea = h('textarea', {placeholder: 'Write a new bog post...'}) } diff --git a/render.js b/render.js index 8ed5cba..6be7f49 100644 --- a/render.js +++ b/render.js @@ -46,9 +46,9 @@ function render (msg, keys, preview) { msg.text = nextPost.text var editedcontents = h('span', {id : 'content:' + msg.key, innerHTML: marked(nextPost.text)}) - - msgcontents.parentNode.replaceChild(editedcontents, msgcontents) - + if (msgcontents) { + msgcontents.parentNode.replaceChild(editedcontents, msgcontents) + } message.appendChild(h('div', [ 'edited in:', h('a', {href: '#' + nextPost.key}, [nextPost.key.substring(0, 10) + '...']) @@ -70,11 +70,11 @@ function render (msg, keys, preview) { var renderer = new marked.Renderer(); renderer.link = function(href, title, text) { - if ((href[0] == '@') || (href[0] == '%')) { - href = '#' + href - } - var link = marked.Renderer.prototype.link.call(this, href, title, text); - return link + if ((href[0] == '@') || (href[0] == '%')) { + href = '#' + href + } + var link = marked.Renderer.prototype.link.call(this, href, title, text); + return link } marked.setOptions({ @@ -123,27 +123,28 @@ function render (msg, keys, preview) { h('a', {href: '#' + msg.reply}, [msg.reply.substring(0, 10) + '...']) ])) } - var gotName = getName(msg.author, keys) - message.appendChild(h('div',{id: 'content:' + msg.key, innerHTML: marked(msg.text)})) - if (!preview) { - message.appendChild(h('button', { - onclick: function () { - if (messageDiv.firstChild) { - messageDiv.insertBefore(h('div', {classList: 'submessage'}, [composer(keys, msg, gotName)]), messageDiv.childNodes[1]) - } else { - messageDiv.appendChild(h('div', {classList: 'submessage'}, [composer(keys, msg, gotName)])) - } - } - }, ['Reply'])) - if (msg.author === keys.publicKey) { + quickName(msg.author).then(name => { + message.appendChild(h('div',{id: 'content:' + msg.key, innerHTML: marked(msg.text)})) + if (!preview) { message.appendChild(h('button', { onclick: function () { - var editor = h('div', [composer(keys, msg, {gotName: false}, {edit: true})]) - message.appendChild(editor) + if (messageDiv.firstChild) { + messageDiv.insertBefore(h('div', {classList: 'submessage'}, [composer(keys, msg, name)]), messageDiv.childNodes[1]) + } else { + messageDiv.appendChild(h('div', {classList: 'submessage'}, [composer(keys, msg, name)])) + } } - }, ['Edit'])) + }, ['Reply'])) + if (msg.author === keys.publicKey) { + message.appendChild(h('button', { + onclick: function () { + var editor = h('div', [composer(keys, msg, {name: false}, {edit: true})]) + message.appendChild(editor) + } + }, ['Edit'])) + } } - } + }) } else if (msg.type == 'name') { var mini = h('span', [' identified ', h('a', {href: '#' + msg.named }, [msg.named.substring(0, 10) + '...']), ' as ' + msg.name]) message.appendChild(getHeader(msg, keys, mini)) diff --git a/views.js b/views.js index 333db18..1758e63 100644 --- a/views.js +++ b/views.js @@ -39,15 +39,18 @@ function profilePage (src, keys) { } }, ['Mentions']) - var respond = h('button', { - onclick: function () { - scroller.insertBefore(composer(keys, msg, gotName), scroller.childNodes[1]) - } - }, ['Reply to ' + gotName.textContent]) + quickName(src).then(name => { + console.log(name) + var respond = h('button', { + onclick: function () { + scroller.insertBefore(composer(keys, msg, name), scroller.childNodes[1]) + } + }, ['Reply to ' + name]) + profile.appendChild(respond) + }) profile.appendChild(identify(src, profile, keys)) profile.appendChild(mentionsButton) - profile.appendChild(respond) if (src != keys.publicKey) { localforage.getItem('subscriptions').then(function (subs) { -- cgit v1.2.3-70-g09d2 From 88b7c75fca9db45611ebdc02af150e56f6818120 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 23 Nov 2019 14:08:31 -0600 Subject: add name to buttons --- views.js | 72 +++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/views.js b/views.js index 1758e63..de61501 100644 --- a/views.js +++ b/views.js @@ -33,54 +33,52 @@ function profilePage (src, keys) { profile.appendChild(h('br')) - var mentionsButton = h('button', { - onclick: function () { - location.href = '#?' + src - } - }, ['Mentions']) - quickName(src).then(name => { - console.log(name) + var mentionsButton = h('button', { + onclick: function () { + location.href = '#?' + src + } + }, [name + '\'s Mentions']) + profile.appendChild(mentionsButton) var respond = h('button', { onclick: function () { scroller.insertBefore(composer(keys, msg, name), scroller.childNodes[1]) } }, ['Reply to ' + name]) profile.appendChild(respond) - }) - profile.appendChild(identify(src, profile, keys)) - profile.appendChild(mentionsButton) + if (src != keys.publicKey) { + localforage.getItem('subscriptions').then(function (subs) { + if (subs.includes(src)) { + profile.appendChild(h('button', { + onclick: function () { + subs = subs.filter(a => a !== src) + localforage.setItem('subscriptions', subs).then(function () { location.reload() }) + } + }, ['Unsubscribe from ' + name])) + } else { + profile.appendChild(h('button', { + onclick: function () { + subs.push(src) + localforage.setItem('subscriptions', subs).then(function () { location.reload() }) + } + }, ['Subscribe to ' + name])) + } + }) + } - if (src != keys.publicKey) { - localforage.getItem('subscriptions').then(function (subs) { - if (subs.includes(src)) { - profile.appendChild(h('button', { - onclick: function () { - subs = subs.filter(a => a !== src) - localforage.setItem('subscriptions', subs).then(function () { location.reload() }) - } - }, ['Unsubscribe'])) - } else { - profile.appendChild(h('button', { - onclick: function () { - subs.push(src) - localforage.setItem('subscriptions', subs).then(function () { location.reload() }) - } - }, ['Subscribe'])) + profile.appendChild(h('button', { + onclick: function () { + localforage.removeItem(src).then(function () { + var home = true + regenerate(home) + }) } - }) - } + }, ['Delete ' + name + '\'s feed'])) + }) + + profile.appendChild(identify(src, profile, keys)) - profile.appendChild(h('button', { - onclick: function () { - localforage.removeItem(src).then(function () { - var home = true - regenerate(home) - }) - } - }, ['Delete feed'])) - async function addPosts (posts, keys) { posts.forEach(function (msg) { if (msg.author === src) { -- cgit v1.2.3-70-g09d2 From 1722c101e1ec4adcb1b016501ca65b804e43ae25 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 23 Nov 2019 14:13:31 -0600 Subject: unused gotName --- views.js | 1 - 1 file changed, 1 deletion(-) diff --git a/views.js b/views.js index de61501..519e3ea 100644 --- a/views.js +++ b/views.js @@ -5,7 +5,6 @@ function threadPage (src, keys) { } function profilePage (src, keys) { - var gotName = getName(src, keys) var msg = {} msg.author = src -- cgit v1.2.3-70-g09d2 From cdcbf89b31a823390ab94c9e66e80a71669b273e Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 23 Nov 2019 18:55:18 -0600 Subject: clean up and move all config and keys to a settings page --- app.js | 10 +++----- css/style.css | 7 +++-- gossip.js | 4 +-- package-lock.json | 21 --------------- package.json | 1 - server.js | 8 ++---- views.js | 76 +++++++++++++++++++++++++++++++------------------------ 7 files changed, 55 insertions(+), 72 deletions(-) diff --git a/app.js b/app.js index 09b2e5d..7fe1ae2 100644 --- a/app.js +++ b/app.js @@ -8,10 +8,8 @@ function route (keys) { var screen = document.getElementById('screen') screen.appendChild(scroller) - if (src === 'key') { - keyPage(keys) - } else if (src === 'pubs') { - pubs() + if (src === 'settings') { + settingsPage(keys) } else if (src[0] === '@') { profilePage(src, keys) } else if (src[0] === '?') { @@ -30,9 +28,7 @@ keys().then(key => { h('div', {classList: 'internal'}, [ h('li', [h('a', {href: '#'}, ['Home'])]), h('li', [h('a', {href: '#' + key.publicKey}, [getName(key.publicKey, keys)])]), - h('li', [h('a', {href: '#key'}, ['Key'])]), - h('li', [h('a', {href: '#pubs'}, ['Pubs'])]), - h('li', {classList: 'right'}, [h('a', {href: 'http://git.sr.ht/~ev/bogbook'}, ['Git'])]), + h('li', {classList: 'right'}, [h('a', {href: '#settings'}, ['Settings'])]), h('form', { classList: 'search', onsubmit: function (e) { window.location.hash = '?' + search.value diff --git a/css/style.css b/css/style.css index fad1090..2aedb05 100644 --- a/css/style.css +++ b/css/style.css @@ -61,6 +61,8 @@ hr { border-radius: 5px; } +#scroller:last-child { margin-bottom: 10em; } + .message, .message > *, .navbar, .navbar > * { animation: fadein .5s; } @@ -167,17 +169,18 @@ textarea { } form.search, input.search { - width: 100px; + width: 175px; float: right; margin: 0; padding: 0; + padding-left: .1em; color: #f5f5f5; background: #444; border-radius: 3px; } form.search { - margin-top: .3em; + margin-top: .20em; } .navbar li.right { diff --git a/gossip.js b/gossip.js index f7ed484..d0fc31c 100644 --- a/gossip.js +++ b/gossip.js @@ -102,7 +102,7 @@ function sync (subs, keys) { open(unboxedreq[i]).then(opened => { log.unshift(opened) var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[2]) + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) if (unboxedreq.length + lastmsg.seq === opened.seq) { log.sort((a, b) => a.timestamp - b.timestamp) var reversed = log.reverse() @@ -155,7 +155,7 @@ function sync (subs, keys) { open(unboxedreq[i]).then(opened => { log.unshift(opened) var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[2]) + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) if (opened.seq === unboxedreq.length) { log.sort((a, b) => a.timestamp - b.timestamp) var reversed = log.reverse() diff --git a/package-lock.json b/package-lock.json index 1571dd4..c684ff2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -83,22 +83,6 @@ "is-wsl": "^1.1.0" } }, - "sanitize-filename": { - "version": "1.6.3", - "resolved": "https://registry.npmjs.org/sanitize-filename/-/sanitize-filename-1.6.3.tgz", - "integrity": "sha512-y/52Mcy7aw3gRm7IrcGDFx/bCk4AhRh2eI9luHOQM86nZsqwiRkkq2GekHXBBD+SmPidc8i2PqtYZl+pWJ8Oeg==", - "requires": { - "truncate-utf8-bytes": "^1.0.0" - } - }, - "truncate-utf8-bytes": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz", - "integrity": "sha1-QFkjkJWS1W94pYGENLC3hInKXys=", - "requires": { - "utf8-byte-length": "^1.0.1" - } - }, "tweetnacl": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.1.tgz", @@ -114,11 +98,6 @@ "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==" }, - "utf8-byte-length": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz", - "integrity": "sha1-9F8VDExm7uloGGUFq5P8u4rWv2E=" - }, "ws": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz", diff --git a/package.json b/package.json index 3386ed5..658ffd8 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,6 @@ "ecstatic": "^4.1.2", "ed2curve": "^0.2.1", "open": "^6.2.0", - "sanitize-filename": "^1.6.3", "tweetnacl": "^1.0.1", "tweetnacl-util": "^0.15.0", "ws": "^6.2.1" diff --git a/server.js b/server.js index e2b2f06..475551a 100644 --- a/server.js +++ b/server.js @@ -1,5 +1,6 @@ // static server (8089) +var fs = require('fs') var http = require('http') var serve = require('ecstatic') var open = require('open') @@ -14,19 +15,14 @@ open('http://localhost:8089') var bog = require('./bog') var WS = require('ws') -var fs = require('fs') var nacl = require('tweetnacl') nacl.util = require('tweetnacl-util') -var homedir = require('os').homedir() -var sanitize = require('sanitize-filename') - +var homedir = require('os').homedir() var bogdir = homedir + '/.bogbook/bogs/' -var blobdir = homedir + '/.bogbook/blobs/' if (!fs.existsSync(homedir + '/.bogbook/')) {fs.mkdirSync(homedir + '/.bogbook/')} if (!fs.existsSync(bogdir)){fs.mkdirSync(bogdir)} -if (!fs.existsSync(blobdir)){fs.mkdirSync(blobdir)} var wserve = new WS.Server({ port: 8080 }) diff --git a/views.js b/views.js index 519e3ea..1cac555 100644 --- a/views.js +++ b/views.js @@ -11,7 +11,7 @@ function profilePage (src, keys) { var profile = h('div', {classList: 'profile'}) scroller.appendChild(profile) - scroller.appendChild(h('div')) + //scroller.appendChild(h('div')) var subs = [src] @@ -144,22 +144,6 @@ function publicPage (keys) { } }) - var div = h('div') - - div.appendChild(h('button', { - onclick: function () { - localforage.clear().then(function () {location.reload()}) - } - }, ['Delete Everything'])) - - div.appendChild(h('button', { - onclick: function () { - regenerate() - } - }, ['Regenerate'])) - - scroller.appendChild(div) - scroller.appendChild(composer(keys)) async function addPosts (posts, keys) { @@ -189,14 +173,18 @@ function publicPage (keys) { }) } -function keyPage (keys) { - var message = h('div', {classList: 'message'}) +function settingsPage (keys) { + var welcome = h('div', {classList: 'message'}) - message.appendChild(h('p', {innerHTML: marked('This is your ed25519 public/private keypair. It was generated using [TweetNaCl.js](https://tweetnacl.js.org/#/). Your public key is your identity when using [Bogbook](http://bogbook.com/), save your key in a safe place so that you can continue to use the same identity.')})) + welcome.appendChild(h('p', {innerHTML: marked('This is [Bogbook](http://bogbook.com), a distributed social network built using secure-gossiped blockchain logging (blogging), but we call them "bogs".\n\n You can view the code at [git.sr.ht/~ev/bogbook](https://git.sr.ht/~ev/bogbook) or clone it directly from our server:\n```\ngit clone http://git.bogbook.com/bogbook.git\n```\n Please communicate errors, bugs, and pull-requests to [@ev](http://bogbook.com/#@Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0=) using Bogbook or via email: [ev@evbogue.com](mailto:ev@evbogue.com)')})) - message.appendChild(h('pre', {style: 'width: 80%'}, [h('code', [JSON.stringify(keys)])])) + var keyDiv = h('div', {classList: 'message'}) - message.appendChild(h('button', { + keyDiv.appendChild(h('p', {innerHTML: marked('This is your ed25519 public/private keypair. It was generated using [TweetNaCl.js](https://tweetnacl.js.org/#/). Your public key is your identity when using Bogbook, save your key in a safe place so that you can continue to use the same identity.')})) + + keyDiv.appendChild(h('pre', {style: 'width: 80%'}, [h('code', [JSON.stringify(keys)])])) + + keyDiv.appendChild(h('button', { onclick: function () { localforage.removeItem('id', function () { location.hash = '' @@ -206,8 +194,8 @@ function keyPage (keys) { }, ['Delete Key'])) var textarea = h('textarea', {placeholder: 'Import your existing ed25519 keypair'}) - message.appendChild(textarea) - message.appendChild(h('button', { + keyDiv.appendChild(textarea) + keyDiv.appendChild(h('button', { onclick: function () { if (textarea.value) { localforage.setItem('id', JSON.parse(textarea.value)).then(function () { location.reload() }) @@ -215,19 +203,37 @@ function keyPage (keys) { } }, ['Import Key'])) - scroller.appendChild(message) -} + var everything = h('div', {classList: 'message'}) + + everything.appendChild(h('p', {innerHTML: marked('Sometimes you may want to delete all of your bogbook data in the browser. When you click this button, Bogbook will erase everything that you\'ve stored in the browser. NOTE: This will not delete Bogbook posts that you have already gossiped with others. WARNING: This will delete your Bogbook keypair as well as all data stored in the browser. If you want to continue to use the same key, make sure you\'ve backed up your keypair!')})) + + everything.appendChild(h('button', { + onclick: function () { + localforage.clear().then(function () {location.reload()}) + } + }, ['Delete Everything'])) + + /* we probably don't need this anymore + var regenerate = h('div', {classList: 'message'}) + + regenerate.appendChild(h('p', {innerHTML: marked('The regenerate button will create a new bogbook log in your browser from all of the feeds that you\'ve collected in your browser. While it is rare, you may use this button to troubleshoot if Bogbook is throwing strange database errors in your console.')})) + + regenerate.appendChild(h('button', { + onclick: function () { + regenerate() + } + }, ['Regenerate']))*/ + -function pubs () { - var message = h('div', {classList: 'message'}) + var pubs = h('div', {classList: 'message'}) - message.appendChild(h('p', {innerHTML: marked('These are the Bogbook pubs that your browser will connect to as it looks for new messages from your subscriptions, when you post new bog posts, and when you click on feeds.\n\nAdd or remove these pubs to control where your Bogbook gossips. Localhost is a default, but will only work if you install Bogbook on your local computer by [cloning down the repo](https://git.sr.ht/~ev/bogbook).')})) + pubs.appendChild(h('p', {innerHTML: marked('These are your bogbook pubs. Bogbook will gossip with these pubs to publish your messages and check for new messages from your subscriptions. You should have at least one Bogbook pub in order to gossip your messages. If you don\'t see a bogbook pub below, try clicking "Reset Pubs" or add \n```\nws://bogbook.com/~@h4e3bHDJeDWiCAkzp83HINPR4y7BLR7tI3fOVqwLQqw=\n```\n to your pubs list.')})) var add = h('input', {placeholder: 'Add a pub'}) localforage.getItem('securepubs').then(function (servers) { - message.appendChild(h('div', [ + pubs.appendChild(h('div', [ add, h('button', { onclick: function () { @@ -240,7 +246,7 @@ function pubs () { ])) servers.forEach(function (pub) { - message.appendChild(h('p', [ + pubs.appendChild(h('p', [ pub, h('button', { onclick: function () { @@ -252,7 +258,7 @@ function pubs () { }) }) - message.appendChild(h('button', { + pubs.appendChild(h('button', { onclick: function () { localforage.removeItem('securepubs').then(function () { location.hash = '' @@ -261,6 +267,10 @@ function pubs () { } }, ['Reset pubs'])) - scroller.appendChild(message) + scroller.appendChild(welcome) + scroller.appendChild(keyDiv) + scroller.appendChild(pubs) + scroller.appendChild(everything) + //scroller.appendChild(regenerate) } -- cgit v1.2.3-70-g09d2 From 4f57aed2bdd158a95e63528956639dc4e09e09c4 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 23 Nov 2019 19:03:39 -0600 Subject: add a media query for small screens so composer is visible --- css/style.css | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/css/style.css b/css/style.css index 2aedb05..e2bf78e 100644 --- a/css/style.css +++ b/css/style.css @@ -36,7 +36,6 @@ hr { margin-bottom: .9em; } - #screen { position: absolute; top: 35px; @@ -51,6 +50,10 @@ hr { margin-left: auto; } +@media only screen and (max-width: 480px) { + #screen { top: 57px; } +} + .right { float: right;} .message, .profile { -- cgit v1.2.3-70-g09d2 From 88f681bb7d3b86b6d3af6af9d124ef3c008730d4 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 23 Nov 2019 19:07:17 -0600 Subject: add a little padding to the sides on smaller screens too --- css/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css/style.css b/css/style.css index e2bf78e..4200941 100644 --- a/css/style.css +++ b/css/style.css @@ -51,7 +51,7 @@ hr { } @media only screen and (max-width: 480px) { - #screen { top: 57px; } + #screen { top: 57px; right: 5px; left: 5px; } } .right { float: right;} -- cgit v1.2.3-70-g09d2 From 06a7740326eebda9076a1b4538defbf0a351a209 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 23 Nov 2019 19:26:47 -0600 Subject: only call quickname on button press --- render.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/render.js b/render.js index 6be7f49..3bd02df 100644 --- a/render.js +++ b/render.js @@ -123,16 +123,18 @@ function render (msg, keys, preview) { h('a', {href: '#' + msg.reply}, [msg.reply.substring(0, 10) + '...']) ])) } - quickName(msg.author).then(name => { + //quickName(msg.author).then(name => { message.appendChild(h('div',{id: 'content:' + msg.key, innerHTML: marked(msg.text)})) if (!preview) { message.appendChild(h('button', { onclick: function () { - if (messageDiv.firstChild) { - messageDiv.insertBefore(h('div', {classList: 'submessage'}, [composer(keys, msg, name)]), messageDiv.childNodes[1]) - } else { - messageDiv.appendChild(h('div', {classList: 'submessage'}, [composer(keys, msg, name)])) - } + quickName(msg.author).then(name => { + if (messageDiv.firstChild) { + messageDiv.insertBefore(h('div', {classList: 'submessage'}, [composer(keys, msg, name)]), messageDiv.childNodes[1]) + } else { + messageDiv.appendChild(h('div', {classList: 'submessage'}, [composer(keys, msg, name)])) + } + }) } }, ['Reply'])) if (msg.author === keys.publicKey) { @@ -144,7 +146,7 @@ function render (msg, keys, preview) { }, ['Edit'])) } } - }) + //}) } else if (msg.type == 'name') { var mini = h('span', [' identified ', h('a', {href: '#' + msg.named }, [msg.named.substring(0, 10) + '...']), ' as ' + msg.name]) message.appendChild(getHeader(msg, keys, mini)) -- cgit v1.2.3-70-g09d2 From 30cdde804f90ca533bc3388de46251f1400087a5 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 24 Nov 2019 09:03:30 -0600 Subject: serve ads if client feeds are up to date --- ads.json | 15 +++++++++++++++ css/style.css | 23 ++++++++++++++++++++++- gossip.js | 4 ++++ index.html | 2 +- package.json | 2 +- render.js | 26 ++++++++++++++++++++++++++ server.js | 25 ++++++++++++++++++------- 7 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 ads.json diff --git a/ads.json b/ads.json new file mode 100644 index 0000000..ada8e83 --- /dev/null +++ b/ads.json @@ -0,0 +1,15 @@ +[ +"Eat your veggies.", +"Drink more coffee.", +"Read my post.", +"Avoid Black Friday.", +"Your ad here.", +"Run your own pub to serve your ads.", +"Run your own pub to turn off ads.", +"Make money online.", +"Hello world.", +"Become a professional bogger.", +"Invite your friends.", +"Bogbook 2020.", +"Tip your bartender." +] diff --git a/css/style.css b/css/style.css index 4200941..2f28584 100644 --- a/css/style.css +++ b/css/style.css @@ -66,10 +66,31 @@ hr { #scroller:last-child { margin-bottom: 10em; } -.message, .message > *, .navbar, .navbar > * { +.message, .message > *, .navbar, .navbar > *, #ad, #ad > * { animation: fadein .5s; } +#ad { + background: white; + font-size: .8em; + border: 1px solid #ddd; + border-radius: 5px; + position: fixed; + padding: .3em .5em; + bottom: 5px; + left: 5px; + width: 250px; +} + +#ad button { + font-size: .8em; + margin: 0; + padding: 0; + padding-left: 5px; padding-right: 5px; + position: absolute; + bottom: 2px; right: 2px; +} + @keyframes fadein { from { opacity: 0; } to { opacity: 1; } diff --git a/gossip.js b/gossip.js index d0fc31c..09f4207 100644 --- a/gossip.js +++ b/gossip.js @@ -48,6 +48,10 @@ function sync (subs, keys) { var req = JSON.parse(message.data) unbox(req.box, req.requester, keys).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) + if (unboxedreq.content) { + console.log(unboxedreq) + renderAd(unboxedreq) + } if (unboxedreq.seq === 0) { var stringedfeed = JSON.stringify(srclog) box(stringedfeed, serverpub, keys).then(boxed => { diff --git a/index.html b/index.html index a663afc..04d275f 100644 --- a/index.html +++ b/index.html @@ -17,8 +17,8 @@ - + diff --git a/package.json b/package.json index 658ffd8..c8799e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bogbook", - "version": "1.6.0", + "version": "1.7.0", "description": "secure blockchain logging (blogging, without the l) -- bogging", "main": "server.js", "scripts": { diff --git a/render.js b/render.js index 3bd02df..ee91c24 100644 --- a/render.js +++ b/render.js @@ -1,3 +1,29 @@ +function renderAd (ad) { + var screen = document.getElementById('screen') + var adspot = document.getElementById('ad') + + if (adspot) { + adspot.parentNode.removeChild(adspot) + } + + newAd = h('div', {id: 'ad'}, [ + h('span', {classList: 'right'}, [h('pre', ['Ad'])]), + h('p', {innerHTML: marked(ad.content)}), + h('button', {classList: 'right', + onclick: function () { + adspot = document.getElementById('ad') + adspot.parentNode.removeChild(adspot) + } + }, ['Heard']), + h('span', [ + '—', + h('a', {href: ad.name}, [ad.name]) + ]) + ]) + + screen.appendChild(newAd) +} + function getHeader (post, keys, mini) { var getRaw = h('button', { onclick: function () { diff --git a/server.js b/server.js index 475551a..112f899 100644 --- a/server.js +++ b/server.js @@ -26,6 +26,8 @@ if (!fs.existsSync(bogdir)){fs.mkdirSync(bogdir)} var wserve = new WS.Server({ port: 8080 }) +var adContents = JSON.parse(fs.readFileSync(__dirname + '/ads.json')) + bog.keys().then(key => { wserve.on('connection', function (ws) { ws.on('message', function (message) { @@ -42,9 +44,23 @@ bog.keys().then(key => { var feed = JSON.parse(data) bog.open(feed[0]).then(msg => { if (unboxedreq.seq === msg.seq) { - console.log(unboxedreq.author + '\'s feed is identical, sending nothing to client') + //console.log(unboxedreq.author + '\'s feed is identical, sending nothing to client') + //commment this section out to disable ads + console.log(unboxedreq.author + '\'s feed is identical, sending an ad to ' + req.requester) + var ad = JSON.stringify({ + author: key.publicKey, + name: 'http://bogbook.com/', + content: adContents[Math.floor(Math.random() * adContents.length)], + timestamp: Date.now() + }) + bog.box(ad, req.requester, key).then(boxed => { + obj = { + requester: key.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) } - if (unboxedreq.seq > msg.seq) { // right now the client is still sending the entire log, which works just fine but isn't optimal console.log('client feed is longer, requesting diff from client') @@ -57,21 +73,18 @@ bog.keys().then(key => { ws.send(JSON.stringify(obj)) }) } - if (unboxedreq.seq < msg.seq) { var endrange = feed.length - unboxedreq.seq - 25 if (endrange < 0) { endrange = feed.length - unboxedreq.seq - 1 } var baserange = feed.length - unboxedreq.seq - console.log('client feed is shorter, sending from ' + baserange + ' to ' + endrange + ' to client') var diff = JSON.stringify( feed.slice( endrange, baserange) ) - //var diff = JSON.stringify(feed.slice(0, msg.seq - unboxedreq.seq)) bog.box(diff, req.requester, key).then(boxed => { var obj = { requester: key.publicKey, @@ -82,7 +95,6 @@ bog.keys().then(key => { } }) } else { - // if we don't have the feed, request the feed from the client and save console.log('We don\'t have the log on the server, requesting log from ' + req.requester ) var reqwhole = JSON.stringify({author: unboxedreq.author, seq: 0}) @@ -96,7 +108,6 @@ bog.keys().then(key => { } }) } else if (Array.isArray(unboxedreq)) { - // first check to make sure that we have an entire log bog.open(unboxedreq[0]).then(msg => { if (msg.seq === unboxedreq.length) { fs.writeFile(bogdir + msg.author, JSON.stringify(unboxedreq), 'UTF-8', function (err, success) { -- cgit v1.2.3-70-g09d2 From 79b1c0e953dad37e4f8f97e2fb297a78e876715b Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 24 Nov 2019 09:54:52 -0600 Subject: slow down gossip a little --- gossip.js | 278 +++++++++++++++++++++++++++++++------------------------------- views.js | 8 +- 2 files changed, 143 insertions(+), 143 deletions(-) diff --git a/gossip.js b/gossip.js index 09f4207..81c3f1c 100644 --- a/gossip.js +++ b/gossip.js @@ -21,22 +21,118 @@ function sync (subs, keys) { wsServers = pubs } }).then(function () { - subs.forEach(function (sub) { - wsServers.forEach(function (server, index) { - setTimeout(function () { - console.log('SYNCING WITH: ' + server + ' to fetch ' + sub) - var split = server.split('~') - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) + subs.forEach(function (sub, index) { + setTimeout(function () { + wsServers.forEach(function (server, index) { + setTimeout(function () { + console.log('SYNCING WITH: ' + server + ' to fetch ' + sub) + var split = server.split('~') + var serverurl = split[0] + var serverpub = split[1] + var ws = new WebSocket(serverurl) - bog(sub).then(srclog => { - if (srclog) { - open(srclog[0]).then(msg => { + bog(sub).then(srclog => { + if (srclog) { + open(srclog[0]).then(msg => { + ws.onopen = function () { + var message = JSON.stringify(msg) + // if we have a log then send the latest log and see if we get anything back + box(message, serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) + } + ws.onmessage = function (message) { + var req = JSON.parse(message.data) + unbox(req.box, req.requester, keys).then(unboxed => { + var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) + if (unboxedreq.content) { + console.log(unboxedreq) + renderAd(unboxedreq) + } + if (unboxedreq.seq === 0) { + var stringedfeed = JSON.stringify(srclog) + box(stringedfeed, serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + console.log('Sending entire log of ' + msg.author + ' to ' + serverpub) + ws.send(JSON.stringify(obj)) + }) + } + + if (unboxedreq.seq > msg.seq) { + console.log('server feed is longer, requesting diff from server') + var reqdiff = JSON.stringify({author: unboxedreq.author, seq: msg.seq}) + box(reqdiff, serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) + } + + if (unboxedreq.seq < msg.seq) { + console.log('server feed is shorter, sending diff to server') + var diff = JSON.stringify(srclog.slice(0, msg.seq - unboxedreq.seq)) + box(diff, serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) + } + + if (Array.isArray(unboxedreq)) { + console.log('received diff from server') + open(unboxedreq[0]).then(msg => { + localforage.getItem(msg.author).then(feed => { + open(feed[0]).then(lastmsg => { + if (unboxedreq.length + lastmsg.seq === msg.seq) { + var newlog = unboxedreq.concat(feed) + localforage.setItem(msg.author, newlog).then(success => { + console.log('combined existing feed of ' + msg.author + ' with diff and saved to client') + }) + localforage.getItem('log').then(log => { + if (!log) { + var log = [] + } + for (var i = unboxedreq.length -1; i >= 0; --i) { + open(unboxedreq[i]).then(opened => { + log.unshift(opened) + var scroller = document.getElementById('scroller') + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + if (unboxedreq.length + lastmsg.seq === opened.seq) { + log.sort((a, b) => a.timestamp - b.timestamp) + var reversed = log.reverse() + localforage.setItem('log', reversed).then(success => { + console.log('saved log with ' + opened.author + ' prepended to localForage') + }) + } + }) + } + }) + } + }) + }) + }) + + } + + }) + } + }) + } else { + console.log('NO LOG IN CLIENT') ws.onopen = function () { - var message = JSON.stringify(msg) - // if we have a log then send the latest log and see if we get anything back - box(message, serverpub, keys).then(boxed => { + var reqwhole = JSON.stringify({author: sub, seq: 0}) + box(reqwhole, serverpub, keys).then(boxed => { var obj = { requester: keys.publicKey, box: boxed @@ -46,140 +142,46 @@ function sync (subs, keys) { } ws.onmessage = function (message) { var req = JSON.parse(message.data) + console.log('received message from ' + req.requester) unbox(req.box, req.requester, keys).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - if (unboxedreq.content) { - console.log(unboxedreq) - renderAd(unboxedreq) - } - if (unboxedreq.seq === 0) { - var stringedfeed = JSON.stringify(srclog) - box(stringedfeed, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - console.log('Sending entire log of ' + msg.author + ' to ' + serverpub) - ws.send(JSON.stringify(obj)) - }) - } - - if (unboxedreq.seq > msg.seq) { - console.log('server feed is longer, requesting diff from server') - var reqdiff = JSON.stringify({author: unboxedreq.author, seq: msg.seq}) - box(reqdiff, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - - if (unboxedreq.seq < msg.seq) { - console.log('server feed is shorter, sending diff to server') - var diff = JSON.stringify(srclog.slice(0, msg.seq - unboxedreq.seq)) - box(diff, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - if (Array.isArray(unboxedreq)) { - console.log('received diff from server') open(unboxedreq[0]).then(msg => { localforage.getItem(msg.author).then(feed => { - open(feed[0]).then(lastmsg => { - if (unboxedreq.length + lastmsg.seq === msg.seq) { - var newlog = unboxedreq.concat(feed) - localforage.setItem(msg.author, newlog).then(success => { - console.log('combined existing feed of ' + msg.author + ' with diff and saved to client') - }) - localforage.getItem('log').then(log => { - if (!log) { - var log = [] - } - for (var i = unboxedreq.length -1; i >= 0; --i) { - open(unboxedreq[i]).then(opened => { - log.unshift(opened) - var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) - if (unboxedreq.length + lastmsg.seq === opened.seq) { - log.sort((a, b) => a.timestamp - b.timestamp) - var reversed = log.reverse() - localforage.setItem('log', reversed).then(success => { - console.log('saved log with ' + opened.author + ' prepended to localForage') - }) - } - }) - } - }) - } - }) + if (!feed) { + localforage.setItem(msg.author, unboxedreq).then(success => { + console.log('saved log of ' + msg.author + ' to localforage') + }) + localforage.getItem('log').then(log => { + if (!log) { + var log = [] + } + for (var i = unboxedreq.length -1; i >= 0; --i) { + open(unboxedreq[i]).then(opened => { + log.unshift(opened) + var scroller = document.getElementById('scroller') + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + if (opened.seq === unboxedreq.length) { + log.sort((a, b) => a.timestamp - b.timestamp) + var reversed = log.reverse() + localforage.setItem('log', reversed).then(success => { + console.log('saved log with ' + opened.author + ' prepended to localForage') + }) + } + }) + } + }) + } }) }) - } - - }) + }) } - }) - } else { - console.log('NO LOG IN CLIENT') - ws.onopen = function () { - var reqwhole = JSON.stringify({author: sub, seq: 0}) - box(reqwhole, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) } - ws.onmessage = function (message) { - var req = JSON.parse(message.data) - console.log('received message from ' + req.requester) - unbox(req.box, req.requester, keys).then(unboxed => { - var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - if (Array.isArray(unboxedreq)) { - open(unboxedreq[0]).then(msg => { - localforage.getItem(msg.author).then(feed => { - if (!feed) { - localforage.setItem(msg.author, unboxedreq).then(success => { - console.log('saved log of ' + msg.author + ' to localforage') - }) - localforage.getItem('log').then(log => { - if (!log) { - var log = [] - } - for (var i = unboxedreq.length -1; i >= 0; --i) { - open(unboxedreq[i]).then(opened => { - log.unshift(opened) - var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) - if (opened.seq === unboxedreq.length) { - log.sort((a, b) => a.timestamp - b.timestamp) - var reversed = log.reverse() - localforage.setItem('log', reversed).then(success => { - console.log('saved log with ' + opened.author + ' prepended to localForage') - }) - } - }) - } - }) - } - }) - }) - } - }) - } - } - }) - }, index * 1000) - }) + }) + }, index * 50000) + }) + }, index * 20000) }) }) } diff --git a/views.js b/views.js index 1cac555..99db90c 100644 --- a/views.js +++ b/views.js @@ -18,7 +18,7 @@ function profilePage (src, keys) { var interval = 1000 timer = function() { if (src === window.location.hash.substring(1)) { - if (interval < 10000) { interval = interval + 200 } + if (interval < 10000) { interval = interval + 100 } sync(subs, keys) setTimeout(timer, interval) } @@ -124,17 +124,15 @@ function searchPage (src, keys) { function publicPage (keys) { localforage.getItem('subscriptions').then(function (subs) { - var interval = 1000 + var interval = 10000 timer = function() { if ('' === window.location.hash.substring(1)) { - if (interval < 10000) { interval = interval + 1000 } + if (interval < 100000) { interval = interval + 1000 } sync(subs, keys) setTimeout(timer, interval) } } - if (subs) { - subs.push(keys.publicKey) timer() } else { var subs = [] -- cgit v1.2.3-70-g09d2 From 7cde50381962971665a8f82a9aeb10b9ee82ae41 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 24 Nov 2019 11:51:27 -0600 Subject: slow down ads a little --- server.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/server.js b/server.js index 112f899..36a86c0 100644 --- a/server.js +++ b/server.js @@ -46,20 +46,23 @@ bog.keys().then(key => { if (unboxedreq.seq === msg.seq) { //console.log(unboxedreq.author + '\'s feed is identical, sending nothing to client') //commment this section out to disable ads - console.log(unboxedreq.author + '\'s feed is identical, sending an ad to ' + req.requester) - var ad = JSON.stringify({ - author: key.publicKey, - name: 'http://bogbook.com/', - content: adContents[Math.floor(Math.random() * adContents.length)], - timestamp: Date.now() - }) - bog.box(ad, req.requester, key).then(boxed => { - obj = { - requester: key.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) + console.log(unboxedreq.author + '\'s feed is identical') + if (Math.floor(Math.random() * 4) == 2) { + console.log('sending an ad to ' + req.requester) + var ad = JSON.stringify({ + author: key.publicKey, + name: 'http://bogbook.com/', + content: adContents[Math.floor(Math.random() * adContents.length)], + timestamp: Date.now() + }) + bog.box(ad, req.requester, key).then(boxed => { + obj = { + requester: key.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) + } } if (unboxedreq.seq > msg.seq) { // right now the client is still sending the entire log, which works just fine but isn't optimal -- cgit v1.2.3-70-g09d2 From fb351efb7377d2f749e4a0dccbfe5e8ef3964de5 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 24 Nov 2019 14:42:59 -0600 Subject: fix composer glitch --- composer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.js b/composer.js index b44b773..5c46fce 100644 --- a/composer.js +++ b/composer.js @@ -66,8 +66,8 @@ function composer (keys, reply, gotName, edit) { messageDiv.removeChild(messageDiv.firstChild) messageDiv = h('div') messageDiv.appendChild(cache) - scroller.insertBefore(messageDiv, scroller.childNodes[2]) - scroller.insertBefore(render(msg, keys), scroller.childNodes[3]) + scroller.insertBefore(messageDiv, scroller.childNodes[1]) + scroller.insertBefore(render(msg, keys), scroller.childNodes[2]) } else { messageDiv.appendChild(render(msg, keys)) } -- cgit v1.2.3-70-g09d2 From 4c1b955f44aa4882967cacf8151f08b40ef3840a Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 24 Nov 2019 15:24:35 -0600 Subject: extract configuration options, and make it possible to run verbose --- server.js | 124 ++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 97 insertions(+), 27 deletions(-) diff --git a/server.js b/server.js index 36a86c0..07697f3 100644 --- a/server.js +++ b/server.js @@ -1,3 +1,72 @@ +const HTTPPORT = 8089 +const WSPORT = 8080 +const URL = 'localhost' +const ADVERTISEMENTS = true + +// const fullURL = 'http://bogbook.com/' +const fullURL = 'http://' + URL + ':' + HTTPPORT + '/' + +if (process.argv[2] === 'verbose') { + var VERBOSE = true +} else { + var VERBOSE = false +} + +console.log('Verbose output is ' + VERBOSE + ' run with `node server verbose` to see all output') +console.log('Advertisements are ' + ADVERTISEMENTS) + +// log messages + +function printAsk(req, unboxedreq) { + if (VERBOSE) { + console.log(req.requester + ' asked for feed ' + unboxedreq.author + ' after sequence ' + unboxedreq.seq) + } +} + +function printNewFeed (msg, req) { + if (VERBOSE) + console.log('Saved full log of ' + msg.author + ' sent by ' + req.requester) + else + console.log('NEW FEED from ' + msg.author) +} + +function printUpdateFeed (msg, req) { + if (VERBOSE) + console.log('combined existing feed of ' + msg.author + ' sent from ' + req.requester + ' with diff and saved to server') + else + console.log('NEW UPDATE from ' + msg.author) +} + +function printNoFeed (msg, req) { + if (VERBOSE) { + console.log('We don\'t have the log on the server, requesting log from ' + req.requester ) + } +} + +function printClientLonger (msg, req) { + if (VERBOSE) { + console.log(req.requester + '\'s feed of ' + msg.author + ' is longer, requesting diff from ' + req.requester) + } +} + +function printClientShorter (msg, req, baserange, endrange) { + if (VERBOSE) { + console.log(req.requester + ' feed of ' + msg.author + ' is shorter, sending from ' + baserange + ' to ' + endrange + ' to ' + req.requester) + } +} + +function printFeedIdentical (msg, req) { + if (VERBOSE) { + console.log(msg.author + '\'s feed sent from ' + req.requester + ' is identical') + } +} + +function printSendAd (msg, req) { + if (VERBOSE) { + console.log('sent ad ' + msg.content + ' to ' + req.requester) + } +} + // static server (8089) var fs = require('fs') @@ -7,9 +76,11 @@ var open = require('open') http.createServer( serve({ root: __dirname}) -).listen(8089) +).listen(HTTPPORT) -open('http://localhost:8089') +open(fullURL) + +console.log('Bogbook is running at: ' + fullURL) // ws server (8080) @@ -24,7 +95,7 @@ var bogdir = homedir + '/.bogbook/bogs/' if (!fs.existsSync(homedir + '/.bogbook/')) {fs.mkdirSync(homedir + '/.bogbook/')} if (!fs.existsSync(bogdir)){fs.mkdirSync(bogdir)} -var wserve = new WS.Server({ port: 8080 }) +var wserve = new WS.Server({ port: WSPORT }) var adContents = JSON.parse(fs.readFileSync(__dirname + '/ads.json')) @@ -38,35 +109,34 @@ bog.keys().then(key => { bog.unbox(req.box, req.requester, key).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) if (unboxedreq.seq >= 0) { - console.log(req.requester + ' asked for feed ' + unboxedreq.author + ' after sequence ' + unboxedreq.seq) + printAsk(req, unboxedreq) fs.readFile(bogdir + unboxedreq.author, 'UTF-8', function (err, data) { if (data) { var feed = JSON.parse(data) bog.open(feed[0]).then(msg => { if (unboxedreq.seq === msg.seq) { - //console.log(unboxedreq.author + '\'s feed is identical, sending nothing to client') - //commment this section out to disable ads - console.log(unboxedreq.author + '\'s feed is identical') - if (Math.floor(Math.random() * 4) == 2) { - console.log('sending an ad to ' + req.requester) - var ad = JSON.stringify({ - author: key.publicKey, - name: 'http://bogbook.com/', - content: adContents[Math.floor(Math.random() * adContents.length)], - timestamp: Date.now() - }) - bog.box(ad, req.requester, key).then(boxed => { - obj = { - requester: key.publicKey, - box: boxed + printFeedIdentical(msg, req) + if (ADVERTISEMENTS) { + if (Math.floor(Math.random() * 4) == 2) { + var ad = { + author: key.publicKey, + name: fullURL, + content: adContents[Math.floor(Math.random() * adContents.length)], + timestamp: Date.now() } - ws.send(JSON.stringify(obj)) - }) + printSendAd(ad, req) + bog.box(JSON.stringify(ad), req.requester, key).then(boxed => { + obj = { + requester: key.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) + } } } if (unboxedreq.seq > msg.seq) { - // right now the client is still sending the entire log, which works just fine but isn't optimal - console.log('client feed is longer, requesting diff from client') + printClientLonger(msg, req) var reqdiff = JSON.stringify({author: unboxedreq.author, seq: msg.seq}) bog.box(reqdiff, req.requester, key).then(boxed => { var obj = { @@ -82,7 +152,7 @@ bog.keys().then(key => { endrange = feed.length - unboxedreq.seq - 1 } var baserange = feed.length - unboxedreq.seq - console.log('client feed is shorter, sending from ' + baserange + ' to ' + endrange + ' to client') + printClientShorter(msg, req, baserange, endrange) var diff = JSON.stringify( feed.slice( endrange, @@ -98,7 +168,7 @@ bog.keys().then(key => { } }) } else { - console.log('We don\'t have the log on the server, requesting log from ' + req.requester ) + printNoFeed(unboxedreq, req) var reqwhole = JSON.stringify({author: unboxedreq.author, seq: 0}) bog.box(reqwhole, req.requester, key).then(boxed => { @@ -114,7 +184,7 @@ bog.keys().then(key => { bog.open(unboxedreq[0]).then(msg => { if (msg.seq === unboxedreq.length) { fs.writeFile(bogdir + msg.author, JSON.stringify(unboxedreq), 'UTF-8', function (err, success) { - console.log('Saved full log of ' + msg.author + ' sent by ' + req.requester) + printNewFeed(msg, req) }) } if (msg.seq > unboxedreq.length) { fs.readFile(bogdir + msg.author, 'UTF-8', function (err, data) { @@ -123,7 +193,7 @@ bog.keys().then(key => { if (unboxedreq.length + lastmsg.seq === msg.seq) { var newlog = unboxedreq.concat(feed) fs.writeFile(bogdir + msg.author, JSON.stringify(newlog), 'UTF-8', function (err, success) { - console.log('combined existing feed of ' + msg.author + ' with diff and saved to server') + printUpdateFeed(msg, req) }) } }) -- cgit v1.2.3-70-g09d2 From b0d71e6dcbef913c05070a9b7d0a7efedd0024ac Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Tue, 26 Nov 2019 11:43:26 -0600 Subject: add an advertisement generator and send views to the client --- ads.js | 32 ++++++++++++++++++++++++++++++++ render.js | 2 +- server.js | 39 ++++++++++++++++++++++++++------------- 3 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 ads.js diff --git a/ads.js b/ads.js new file mode 100644 index 0000000..efa1bc8 --- /dev/null +++ b/ads.js @@ -0,0 +1,32 @@ +var fs = require('fs') +var nacl = require('tweetnacl') + nacl.util = require('tweetnacl-util') + +var homedir = require('os').homedir() +var addir = homedir + '/.bogbook/ads/' + +if (!fs.existsSync(homedir + '/.bogbook/')) {fs.mkdirSync(homedir + '/.bogbook/')} +if (!fs.existsSync(addir)){fs.mkdirSync(addir)} + +function makeAd (ad) { + console.log(ad) + + var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(ad))).toString('hex') + + var obj = { + hash: hex, + ad: ad, + views: 0 + } + + fs.writeFile(addir + hex, JSON.stringify(obj), 'UTF-8', function () { + console.log('Saved as ' + hex) + }) +} + +if (process.argv[2]) { + var ad = process.argv[2] + makeAd(ad) +} else { + console.log('Please write an ad. Ex: `node ads.js "Hello World"') +} diff --git a/render.js b/render.js index ee91c24..90bb399 100644 --- a/render.js +++ b/render.js @@ -7,7 +7,7 @@ function renderAd (ad) { } newAd = h('div', {id: 'ad'}, [ - h('span', {classList: 'right'}, [h('pre', ['Ad'])]), + h('span', {classList: 'right'}, [h('pre', [ad.views + ' views'])]), h('p', {innerHTML: marked(ad.content)}), h('button', {classList: 'right', onclick: function () { diff --git a/server.js b/server.js index 07697f3..6d22135 100644 --- a/server.js +++ b/server.js @@ -91,6 +91,7 @@ var nacl = require('tweetnacl') var homedir = require('os').homedir() var bogdir = homedir + '/.bogbook/bogs/' +var addir = homedir + '/.bogbook/ads/' if (!fs.existsSync(homedir + '/.bogbook/')) {fs.mkdirSync(homedir + '/.bogbook/')} if (!fs.existsSync(bogdir)){fs.mkdirSync(bogdir)} @@ -118,19 +119,31 @@ bog.keys().then(key => { printFeedIdentical(msg, req) if (ADVERTISEMENTS) { if (Math.floor(Math.random() * 4) == 2) { - var ad = { - author: key.publicKey, - name: fullURL, - content: adContents[Math.floor(Math.random() * adContents.length)], - timestamp: Date.now() - } - printSendAd(ad, req) - bog.box(JSON.stringify(ad), req.requester, key).then(boxed => { - obj = { - requester: key.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) + fs.readdir(addir, function (err, adfiles) { + var num = Math.floor(Math.random() * (adfiles.length)) + console.log(num) + fs.readFile(addir + adfiles[num], 'UTF-8', function (err, adFile) { + console.log(adFile) + var obj = JSON.parse(adFile) + console.log(obj) + var ad = { + author: key.publicKey, + name: fullURL, + content: obj.ad, + timestamp: Date.now(), + views: obj.views + } + obj.views++ + fs.writeFileSync(addir + obj.hash, JSON.stringify(obj), 'UTF-8') + printSendAd(ad, req) + bog.box(JSON.stringify(ad), req.requester, key).then(boxed => { + sendobj = { + requester: key.publicKey, + box: boxed + } + ws.send(JSON.stringify(sendobj)) + }) + }) }) } } -- cgit v1.2.3-70-g09d2 From c9ff925f2268e5f65d3ac52a895e5f1dd386187b Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Tue, 26 Nov 2019 17:31:36 -0600 Subject: roll out ad views --- render.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/render.js b/render.js index 90bb399..d07e204 100644 --- a/render.js +++ b/render.js @@ -6,8 +6,16 @@ function renderAd (ad) { adspot.parentNode.removeChild(adspot) } + var adspace = h('span') + + if (ad.views) { + adspace.appendChild(h('span', {classList: 'right'}, [h('pre', [ad.views + ' views'])])) + } else { + adspace.appendChild(h('span', {classList: 'right'}, [h('pre', ['ad'])])) + } + newAd = h('div', {id: 'ad'}, [ - h('span', {classList: 'right'}, [h('pre', [ad.views + ' views'])]), + adspace, h('p', {innerHTML: marked(ad.content)}), h('button', {classList: 'right', onclick: function () { -- cgit v1.2.3-70-g09d2 From 771bfa53ca1907a1c6cd9a379f844f424592f41a Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Thu, 28 Nov 2019 09:14:46 -0600 Subject: ads are now handled with ads.js --- ads.json | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 ads.json diff --git a/ads.json b/ads.json deleted file mode 100644 index ada8e83..0000000 --- a/ads.json +++ /dev/null @@ -1,15 +0,0 @@ -[ -"Eat your veggies.", -"Drink more coffee.", -"Read my post.", -"Avoid Black Friday.", -"Your ad here.", -"Run your own pub to serve your ads.", -"Run your own pub to turn off ads.", -"Make money online.", -"Hello world.", -"Become a professional bogger.", -"Invite your friends.", -"Bogbook 2020.", -"Tip your bartender." -] -- cgit v1.2.3-70-g09d2 From e1f40329ea6a19d38efc2b39196527a271050f02 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 1 Dec 2019 08:34:01 -0600 Subject: generate an ad if there is not one already --- ads.js | 9 ++++++++- server.js | 50 +++++++++++++++++++++++++------------------------- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/ads.js b/ads.js index efa1bc8..b8ecab9 100644 --- a/ads.js +++ b/ads.js @@ -8,7 +8,7 @@ var addir = homedir + '/.bogbook/ads/' if (!fs.existsSync(homedir + '/.bogbook/')) {fs.mkdirSync(homedir + '/.bogbook/')} if (!fs.existsSync(addir)){fs.mkdirSync(addir)} -function makeAd (ad) { +function make (ad) { console.log(ad) var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(ad))).toString('hex') @@ -27,6 +27,13 @@ function makeAd (ad) { if (process.argv[2]) { var ad = process.argv[2] makeAd(ad) +} if (ad) { + console.log(ad) + makeAd(ad) } else { console.log('Please write an ad. Ex: `node ads.js "Hello World"') } + +module.exports = { + make +} diff --git a/server.js b/server.js index 6d22135..ad23040 100644 --- a/server.js +++ b/server.js @@ -3,7 +3,8 @@ const WSPORT = 8080 const URL = 'localhost' const ADVERTISEMENTS = true -// const fullURL = 'http://bogbook.com/' +var ads = require('./ads') + const fullURL = 'http://' + URL + ':' + HTTPPORT + '/' if (process.argv[2] === 'verbose') { @@ -98,8 +99,6 @@ if (!fs.existsSync(bogdir)){fs.mkdirSync(bogdir)} var wserve = new WS.Server({ port: WSPORT }) -var adContents = JSON.parse(fs.readFileSync(__dirname + '/ads.json')) - bog.keys().then(key => { wserve.on('connection', function (ws) { ws.on('message', function (message) { @@ -120,30 +119,31 @@ bog.keys().then(key => { if (ADVERTISEMENTS) { if (Math.floor(Math.random() * 4) == 2) { fs.readdir(addir, function (err, adfiles) { - var num = Math.floor(Math.random() * (adfiles.length)) - console.log(num) - fs.readFile(addir + adfiles[num], 'UTF-8', function (err, adFile) { - console.log(adFile) - var obj = JSON.parse(adFile) - console.log(obj) - var ad = { - author: key.publicKey, - name: fullURL, - content: obj.ad, - timestamp: Date.now(), - views: obj.views - } - obj.views++ - fs.writeFileSync(addir + obj.hash, JSON.stringify(obj), 'UTF-8') - printSendAd(ad, req) - bog.box(JSON.stringify(ad), req.requester, key).then(boxed => { - sendobj = { - requester: key.publicKey, - box: boxed + if (adfiles[0]) { + var num = Math.floor(Math.random() * (adfiles.length)) + fs.readFile(addir + adfiles[num], 'UTF-8', function (err, adFile) { + var obj = JSON.parse(adFile) + var ad = { + author: key.publicKey, + name: fullURL, + content: obj.ad, + timestamp: Date.now(), + views: obj.views } - ws.send(JSON.stringify(sendobj)) + obj.views++ + fs.writeFileSync(addir + obj.hash, JSON.stringify(obj), 'UTF-8') + printSendAd(ad, req) + bog.box(JSON.stringify(ad), req.requester, key).then(boxed => { + sendobj = { + requester: key.publicKey, + box: boxed + } + ws.send(JSON.stringify(sendobj)) + }) }) - }) + } else { + ads.make('Hello World.') + } }) } } -- cgit v1.2.3-70-g09d2 From 76a421ebd44baa7befa4da8783e5fc5e97261342 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 1 Dec 2019 08:34:08 -0600 Subject: style tweaks --- css/style.css | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/css/style.css b/css/style.css index 2f28584..96a50e7 100644 --- a/css/style.css +++ b/css/style.css @@ -214,7 +214,6 @@ form.search { margin-right: 1.7em; float: right; list-style-type: none; - background: #333; border-radius: 100%; } @@ -236,7 +235,7 @@ button { display: inline-block; *display: inline; padding: 4px 12px; - margin-top: 0; + margin-top: 5px; margin-bottom: 0; *margin-left: .3em; font-size: 14px; -- cgit v1.2.3-70-g09d2 From c989d2c61ae4b99e3cb3f6659a88677497bf86fd Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 1 Dec 2019 08:38:19 -0600 Subject: fix function name --- ads.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ads.js b/ads.js index b8ecab9..c384e6e 100644 --- a/ads.js +++ b/ads.js @@ -26,7 +26,7 @@ function make (ad) { if (process.argv[2]) { var ad = process.argv[2] - makeAd(ad) + make(ad) } if (ad) { console.log(ad) makeAd(ad) -- cgit v1.2.3-70-g09d2 From bd44a80c92e43c7484a7c95b513d8bb8fdef79ad Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 1 Dec 2019 08:41:12 -0600 Subject: fix issue --- ads.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/ads.js b/ads.js index c384e6e..d001f70 100644 --- a/ads.js +++ b/ads.js @@ -27,12 +27,7 @@ function make (ad) { if (process.argv[2]) { var ad = process.argv[2] make(ad) -} if (ad) { - console.log(ad) - makeAd(ad) -} else { - console.log('Please write an ad. Ex: `node ads.js "Hello World"') -} +} module.exports = { make -- cgit v1.2.3-70-g09d2 From dca488003d1f57db840fb9473e61a22a15b96ed7 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 7 Dec 2019 07:27:33 -0600 Subject: clean up --- bog.js | 7 +++---- css/style.css | 6 +++--- gossip.js | 24 ++++++++++++------------ 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/bog.js b/bog.js index 49d0b52..c5cb679 100644 --- a/bog.js +++ b/bog.js @@ -12,7 +12,6 @@ if ((typeof process !== 'undefined') && (process.release.name === 'node')) { // EX: open(msg).then(content => { console.log(content) }) async function open (msg) { - var pubkey = nacl.util.decodeBase64(msg.author.substring(1)) var sig = nacl.util.decodeBase64(msg.signature) var opened = await JSON.parse(nacl.util.encodeUTF8(nacl.sign.open(sig, pubkey))) @@ -139,7 +138,7 @@ function getName (id, keys) { localforage.getItem('name:' + id).then(cache => { if (cache) { - console.log(cache) + //console.log(cache) return name.textContent = '@' + cache } else { bog().then(log => { @@ -182,7 +181,7 @@ function regenerate (home) { if (key[0] == '@') { newlog = newlog.concat(value) } - console.log(newlog) + //console.log(newlog) }).then(function () { newlog.forEach(function (msg) { var pubkey = nacl.util.decodeBase64(msg.author.substring(1)) @@ -192,7 +191,7 @@ function regenerate (home) { openedlog.push(opened) }) - console.log(openedlog) + //console.log(openedlog) openedlog.sort((a, b) => a.timestamp - b.timestamp) diff --git a/css/style.css b/css/style.css index 96a50e7..bdd1c6b 100644 --- a/css/style.css +++ b/css/style.css @@ -45,7 +45,7 @@ hr { } #scroller { - max-width: 50em; + max-width: 680px; margin-right: auto; margin-left: auto; } @@ -172,8 +172,8 @@ textarea { position: fixed; z-index: 1000; margin: 0; - padding-top: .3em; - padding-bottom: .3em; + padding-top: .33em; + padding-bottom: .27em; left: 0; right: 0; top: 0; } diff --git a/gossip.js b/gossip.js index 81c3f1c..d0b91f1 100644 --- a/gossip.js +++ b/gossip.js @@ -25,7 +25,7 @@ function sync (subs, keys) { setTimeout(function () { wsServers.forEach(function (server, index) { setTimeout(function () { - console.log('SYNCING WITH: ' + server + ' to fetch ' + sub) + //console.log('SYNCING WITH: ' + server + ' to fetch ' + sub) var split = server.split('~') var serverurl = split[0] var serverpub = split[1] @@ -50,7 +50,7 @@ function sync (subs, keys) { unbox(req.box, req.requester, keys).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) if (unboxedreq.content) { - console.log(unboxedreq) + unboxedreq.signature = unboxedreq.content renderAd(unboxedreq) } if (unboxedreq.seq === 0) { @@ -60,13 +60,13 @@ function sync (subs, keys) { requester: keys.publicKey, box: boxed } - console.log('Sending entire log of ' + msg.author + ' to ' + serverpub) + //console.log('Sending entire log of ' + msg.author + ' to ' + serverpub) ws.send(JSON.stringify(obj)) }) } if (unboxedreq.seq > msg.seq) { - console.log('server feed is longer, requesting diff from server') + //console.log('server feed is longer, requesting diff from server') var reqdiff = JSON.stringify({author: unboxedreq.author, seq: msg.seq}) box(reqdiff, serverpub, keys).then(boxed => { var obj = { @@ -78,7 +78,7 @@ function sync (subs, keys) { } if (unboxedreq.seq < msg.seq) { - console.log('server feed is shorter, sending diff to server') + //console.log('server feed is shorter, sending diff to server') var diff = JSON.stringify(srclog.slice(0, msg.seq - unboxedreq.seq)) box(diff, serverpub, keys).then(boxed => { var obj = { @@ -90,14 +90,14 @@ function sync (subs, keys) { } if (Array.isArray(unboxedreq)) { - console.log('received diff from server') + //console.log('received diff from server') open(unboxedreq[0]).then(msg => { localforage.getItem(msg.author).then(feed => { open(feed[0]).then(lastmsg => { if (unboxedreq.length + lastmsg.seq === msg.seq) { var newlog = unboxedreq.concat(feed) localforage.setItem(msg.author, newlog).then(success => { - console.log('combined existing feed of ' + msg.author + ' with diff and saved to client') + //console.log('combined existing feed of ' + msg.author + ' with diff and saved to client') }) localforage.getItem('log').then(log => { if (!log) { @@ -112,7 +112,7 @@ function sync (subs, keys) { log.sort((a, b) => a.timestamp - b.timestamp) var reversed = log.reverse() localforage.setItem('log', reversed).then(success => { - console.log('saved log with ' + opened.author + ' prepended to localForage') + //console.log('saved log with ' + opened.author + ' prepended to localForage') }) } }) @@ -129,7 +129,7 @@ function sync (subs, keys) { } }) } else { - console.log('NO LOG IN CLIENT') + //console.log('NO LOG IN CLIENT') ws.onopen = function () { var reqwhole = JSON.stringify({author: sub, seq: 0}) box(reqwhole, serverpub, keys).then(boxed => { @@ -142,7 +142,7 @@ function sync (subs, keys) { } ws.onmessage = function (message) { var req = JSON.parse(message.data) - console.log('received message from ' + req.requester) + //console.log('received message from ' + req.requester) unbox(req.box, req.requester, keys).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) if (Array.isArray(unboxedreq)) { @@ -150,7 +150,7 @@ function sync (subs, keys) { localforage.getItem(msg.author).then(feed => { if (!feed) { localforage.setItem(msg.author, unboxedreq).then(success => { - console.log('saved log of ' + msg.author + ' to localforage') + //console.log('saved log of ' + msg.author + ' to localforage') }) localforage.getItem('log').then(log => { if (!log) { @@ -165,7 +165,7 @@ function sync (subs, keys) { log.sort((a, b) => a.timestamp - b.timestamp) var reversed = log.reverse() localforage.setItem('log', reversed).then(success => { - console.log('saved log with ' + opened.author + ' prepended to localForage') + //console.log('saved log with ' + opened.author + ' prepended to localForage') }) } }) -- cgit v1.2.3-70-g09d2 From f574b936cf06efac899f6dfea2681a3c59fd2fa6 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 7 Dec 2019 07:27:54 -0600 Subject: break settings into own route and make it possible for guests to post advertisements --- index.html | 1 + render.js | 37 ++++++++------- server.js | 32 +++++++++++-- settings.js | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ views.js | 105 +----------------------------------------- 5 files changed, 201 insertions(+), 123 deletions(-) create mode 100644 settings.js diff --git a/index.html b/index.html index 04d275f..0396bcc 100644 --- a/index.html +++ b/index.html @@ -16,6 +16,7 @@ + diff --git a/render.js b/render.js index d07e204..27b8fb4 100644 --- a/render.js +++ b/render.js @@ -14,22 +14,27 @@ function renderAd (ad) { adspace.appendChild(h('span', {classList: 'right'}, [h('pre', ['ad'])])) } - newAd = h('div', {id: 'ad'}, [ - adspace, - h('p', {innerHTML: marked(ad.content)}), - h('button', {classList: 'right', - onclick: function () { - adspot = document.getElementById('ad') - adspot.parentNode.removeChild(adspot) - } - }, ['Heard']), - h('span', [ - '—', - h('a', {href: ad.name}, [ad.name]) - ]) - ]) - - screen.appendChild(newAd) + open(ad).then(opened => { + quickName(ad.author).then(gotName => { + newAd = h('div', {id: 'ad'}, [ + adspace, + h('p', {innerHTML: marked(opened)}), + h('button', {classList: 'right', + onclick: function () { + adspot = document.getElementById('ad') + adspot.parentNode.removeChild(adspot) + } + }, ['Heard']), + h('span', [ + '—', + h('a', {href: '#' + ad.author}, [gotName]), + ' from ', + h('a', {href: ad.name}, [ad.name]) + ]) + ]) + screen.appendChild(newAd) + }) + }) } function getHeader (post, keys, mini) { diff --git a/server.js b/server.js index ad23040..8f7d1c3 100644 --- a/server.js +++ b/server.js @@ -108,6 +108,22 @@ bog.keys().then(key => { } else { bog.unbox(req.box, req.requester, key).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) + if (unboxedreq.type == 'ad') { + + var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.signature))).toString('hex') + + var obj = { + hash: hex, + author: unboxedreq.author, + signature: unboxedreq.signature, + views: 0 + } + + fs.writeFile(addir + hex, JSON.stringify(obj), 'UTF-8', function () { + console.log('Saved as ' + hex) + }) + ws.close() + } if (unboxedreq.seq >= 0) { printAsk(req, unboxedreq) fs.readFile(bogdir + unboxedreq.author, 'UTF-8', function (err, data) { @@ -124,21 +140,28 @@ bog.keys().then(key => { fs.readFile(addir + adfiles[num], 'UTF-8', function (err, adFile) { var obj = JSON.parse(adFile) var ad = { - author: key.publicKey, + author: obj.author, name: fullURL, - content: obj.ad, + content: obj.signature, timestamp: Date.now(), views: obj.views } - obj.views++ - fs.writeFileSync(addir + obj.hash, JSON.stringify(obj), 'UTF-8') + if ((obj.views > 100) && (obj.author != '@Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0=')) { + fs.unlinkSync(addir + obj.hash) + //console.log('REMOVING AD') + } else { + obj.views++ + fs.writeFileSync(addir + obj.hash, JSON.stringify(obj), 'UTF-8') + } printSendAd(ad, req) + //console.log('SENDING AD') bog.box(JSON.stringify(ad), req.requester, key).then(boxed => { sendobj = { requester: key.publicKey, box: boxed } ws.send(JSON.stringify(sendobj)) + ws.close() }) }) } else { @@ -177,6 +200,7 @@ bog.keys().then(key => { box: boxed } ws.send(JSON.stringify(obj)) + ws.close() }) } }) diff --git a/settings.js b/settings.js new file mode 100644 index 0000000..51dc1f2 --- /dev/null +++ b/settings.js @@ -0,0 +1,149 @@ +function settingsPage (keys) { + var welcome = h('div', {classList: 'message'}) + + welcome.appendChild(h('p', {innerHTML: marked('This is [Bogbook](http://bogbook.com), a distributed social network built using secure-gossiped blockchain logging (blogging), but we call them "bogs".\n\n You can view the code at [git.sr.ht/~ev/bogbook](https://git.sr.ht/~ev/bogbook) or clone it directly from our server:\n```\ngit clone http://git.bogbook.com/bogbook.git\n```\n Please communicate errors, bugs, and pull-requests to [@ev](http://bogbook.com/#@Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0=) using Bogbook or via email: [ev@evbogue.com](mailto:ev@evbogue.com)')})) + + var keyDiv = h('div', {classList: 'message'}) + + keyDiv.appendChild(h('p', {innerHTML: marked('This is your ed25519 public/private keypair. It was generated using [TweetNaCl.js](https://tweetnacl.js.org/#/). Your public key is your identity when using Bogbook, save your key in a safe place so that you can continue to use the same identity.')})) + + keyDiv.appendChild(h('pre', {style: 'width: 80%'}, [h('code', [JSON.stringify(keys)])])) + + keyDiv.appendChild(h('button', { + onclick: function () { + localforage.removeItem('id', function () { + location.hash = '' + location.reload() + }) + } + }, ['Delete Key'])) + + var textarea = h('textarea', {placeholder: 'Import your existing ed25519 keypair'}) + keyDiv.appendChild(textarea) + keyDiv.appendChild(h('button', { + onclick: function () { + if (textarea.value) { + localforage.setItem('id', JSON.parse(textarea.value)).then(function () { location.reload() }) + } + } + }, ['Import Key'])) + + var everything = h('div', {classList: 'message'}) + + everything.appendChild(h('p', {innerHTML: marked('Sometimes you may want to delete all of your bogbook data in the browser. When you click this button, Bogbook will erase everything that you\'ve stored in the browser. NOTE: This will not delete Bogbook posts that you have already gossiped with others. WARNING: This will delete your Bogbook keypair as well as all data stored in the browser. If you want to continue to use the same key, make sure you\'ve backed up your keypair!')})) + + everything.appendChild(h('button', { + onclick: function () { + localforage.clear().then(function () {location.reload()}) + } + }, ['Delete Everything'])) + + /* we probably don't need this anymore + var regenerate = h('div', {classList: 'message'}) + + regenerate.appendChild(h('p', {innerHTML: marked('The regenerate button will create a new bogbook log in your browser from all of the feeds that you\'ve collected in your browser. While it is rare, you may use this button to troubleshoot if Bogbook is throwing strange database errors in your console.')})) + + regenerate.appendChild(h('button', { + onclick: function () { + regenerate() + } + }, ['Regenerate']))*/ + + + var pubs = h('div', {classList: 'message'}) + + pubs.appendChild(h('p', {innerHTML: marked('These are your bogbook pubs. Bogbook will gossip with these pubs to publish your messages and check for new messages from your subscriptions. You should have at least one Bogbook pub in order to gossip your messages. If you don\'t see a bogbook pub below, try clicking "Reset Pubs" or add \n```\nws://bogbook.com/~@h4e3bHDJeDWiCAkzp83HINPR4y7BLR7tI3fOVqwLQqw=\n```\n to your pubs list.')})) + + var add = h('input', {placeholder: 'Add a pub'}) + + var pubslist = h('select') + + localforage.getItem('securepubs').then(function (servers) { + + + pubs.appendChild(h('div', [ + add, + h('button', { + onclick: function () { + if (add.value) { + servers.push(add.value) + localforage.setItem('securepubs', servers).then(function () { location.reload() }) + } + } + }, ['Add a pub']) + ])) + + servers.forEach(function (pub) { + pubslist.appendChild( + h('option', {value: pub}, [pub]) + ) + pubs.appendChild(h('p', [ + pub, + h('button', { + onclick: function () { + var newServers = servers.filter(item => item !== pub) + localforage.setItem('securepubs', newServers).then(function () { location.reload() }) + } + }, ['Remove']) + ])) + }) + }) + + pubs.appendChild(h('button', { + onclick: function () { + localforage.removeItem('securepubs').then(function () { + location.hash = '' + location.reload() + }) + } + }, ['Reset pubs'])) + + var ads = h('div', {classList: 'message'}) + + + ads.appendChild(h('span', {innerHTML: marked('Submit an advertisement. Right now advertisements are free for anyone to post to this pub. Ads from guests will run for 100 views before they are deleted by the pub. \n\nSelect a pub:')})) + + ads.appendChild(pubslist) + + var adstext = h('input', {placeholder: 'Hello World!'}) + + ads.appendChild(h('span', [ + h('br'), + ' Write an ad: ', + h('br'), + adstext, + h('button', { + onclick: function () { + var split = pubslist.value.split('~') + console.log(split) + var serverurl = split[0] + var serverpub = split[1] + var ws = new WebSocket(serverurl) + + var msg = { + type: 'ad', + author: keys.publicKey + } + msg.signature = nacl.util.encodeBase64(nacl.sign(nacl.util.decodeUTF8(JSON.stringify(adstext.value)), nacl.util.decodeBase64(keys.privateKey))) + ws.onopen = function () { + box(JSON.stringify(msg), serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) + } + adstext.value = '' + } + }, ['Publish']) + ])) + + scroller.appendChild(welcome) + scroller.appendChild(keyDiv) + scroller.appendChild(pubs) + scroller.appendChild(everything) + //scroller.appendChild(regenerate) + scroller.appendChild(ads) +} + diff --git a/views.js b/views.js index 99db90c..9ec0af6 100644 --- a/views.js +++ b/views.js @@ -98,7 +98,7 @@ function profilePage (src, keys) { if (src === window.location.hash.substring(1)) { addPosts(posts, keys) } - console.log("Bottom of page"); + //console.log("Bottom of page"); } } }) @@ -163,7 +163,7 @@ function publicPage (keys) { if ('' === window.location.hash.substring(1)) { addPosts(posts, keys) } - console.log("Bottom of page"); + //console.log("Bottom of page"); } } }) @@ -171,104 +171,3 @@ function publicPage (keys) { }) } -function settingsPage (keys) { - var welcome = h('div', {classList: 'message'}) - - welcome.appendChild(h('p', {innerHTML: marked('This is [Bogbook](http://bogbook.com), a distributed social network built using secure-gossiped blockchain logging (blogging), but we call them "bogs".\n\n You can view the code at [git.sr.ht/~ev/bogbook](https://git.sr.ht/~ev/bogbook) or clone it directly from our server:\n```\ngit clone http://git.bogbook.com/bogbook.git\n```\n Please communicate errors, bugs, and pull-requests to [@ev](http://bogbook.com/#@Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0=) using Bogbook or via email: [ev@evbogue.com](mailto:ev@evbogue.com)')})) - - var keyDiv = h('div', {classList: 'message'}) - - keyDiv.appendChild(h('p', {innerHTML: marked('This is your ed25519 public/private keypair. It was generated using [TweetNaCl.js](https://tweetnacl.js.org/#/). Your public key is your identity when using Bogbook, save your key in a safe place so that you can continue to use the same identity.')})) - - keyDiv.appendChild(h('pre', {style: 'width: 80%'}, [h('code', [JSON.stringify(keys)])])) - - keyDiv.appendChild(h('button', { - onclick: function () { - localforage.removeItem('id', function () { - location.hash = '' - location.reload() - }) - } - }, ['Delete Key'])) - - var textarea = h('textarea', {placeholder: 'Import your existing ed25519 keypair'}) - keyDiv.appendChild(textarea) - keyDiv.appendChild(h('button', { - onclick: function () { - if (textarea.value) { - localforage.setItem('id', JSON.parse(textarea.value)).then(function () { location.reload() }) - } - } - }, ['Import Key'])) - - var everything = h('div', {classList: 'message'}) - - everything.appendChild(h('p', {innerHTML: marked('Sometimes you may want to delete all of your bogbook data in the browser. When you click this button, Bogbook will erase everything that you\'ve stored in the browser. NOTE: This will not delete Bogbook posts that you have already gossiped with others. WARNING: This will delete your Bogbook keypair as well as all data stored in the browser. If you want to continue to use the same key, make sure you\'ve backed up your keypair!')})) - - everything.appendChild(h('button', { - onclick: function () { - localforage.clear().then(function () {location.reload()}) - } - }, ['Delete Everything'])) - - /* we probably don't need this anymore - var regenerate = h('div', {classList: 'message'}) - - regenerate.appendChild(h('p', {innerHTML: marked('The regenerate button will create a new bogbook log in your browser from all of the feeds that you\'ve collected in your browser. While it is rare, you may use this button to troubleshoot if Bogbook is throwing strange database errors in your console.')})) - - regenerate.appendChild(h('button', { - onclick: function () { - regenerate() - } - }, ['Regenerate']))*/ - - - var pubs = h('div', {classList: 'message'}) - - pubs.appendChild(h('p', {innerHTML: marked('These are your bogbook pubs. Bogbook will gossip with these pubs to publish your messages and check for new messages from your subscriptions. You should have at least one Bogbook pub in order to gossip your messages. If you don\'t see a bogbook pub below, try clicking "Reset Pubs" or add \n```\nws://bogbook.com/~@h4e3bHDJeDWiCAkzp83HINPR4y7BLR7tI3fOVqwLQqw=\n```\n to your pubs list.')})) - - var add = h('input', {placeholder: 'Add a pub'}) - - localforage.getItem('securepubs').then(function (servers) { - - pubs.appendChild(h('div', [ - add, - h('button', { - onclick: function () { - if (add.value) { - servers.push(add.value) - localforage.setItem('securepubs', servers).then(function () { location.reload() }) - } - } - }, ['Add a pub']) - ])) - - servers.forEach(function (pub) { - pubs.appendChild(h('p', [ - pub, - h('button', { - onclick: function () { - var newServers = servers.filter(item => item !== pub) - localforage.setItem('securepubs', newServers).then(function () { location.reload() }) - } - }, ['Remove']) - ])) - }) - }) - - pubs.appendChild(h('button', { - onclick: function () { - localforage.removeItem('securepubs').then(function () { - location.hash = '' - location.reload() - }) - } - }, ['Reset pubs'])) - - scroller.appendChild(welcome) - scroller.appendChild(keyDiv) - scroller.appendChild(pubs) - scroller.appendChild(everything) - //scroller.appendChild(regenerate) -} - -- cgit v1.2.3-70-g09d2 From d3b9afa4e0e959c71ac0894d374821efff96777a Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 7 Dec 2019 11:41:29 -0600 Subject: you can post ads now from the client --- ads.js | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 ads.js diff --git a/ads.js b/ads.js deleted file mode 100644 index d001f70..0000000 --- a/ads.js +++ /dev/null @@ -1,34 +0,0 @@ -var fs = require('fs') -var nacl = require('tweetnacl') - nacl.util = require('tweetnacl-util') - -var homedir = require('os').homedir() -var addir = homedir + '/.bogbook/ads/' - -if (!fs.existsSync(homedir + '/.bogbook/')) {fs.mkdirSync(homedir + '/.bogbook/')} -if (!fs.existsSync(addir)){fs.mkdirSync(addir)} - -function make (ad) { - console.log(ad) - - var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(ad))).toString('hex') - - var obj = { - hash: hex, - ad: ad, - views: 0 - } - - fs.writeFile(addir + hex, JSON.stringify(obj), 'UTF-8', function () { - console.log('Saved as ' + hex) - }) -} - -if (process.argv[2]) { - var ad = process.argv[2] - make(ad) -} - -module.exports = { - make -} -- cgit v1.2.3-70-g09d2 From 8bce6804c197299f473776da758273b92c0fef70 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 8 Dec 2019 10:15:37 -0600 Subject: move from ecstatic to koa, because ecstatic is deprecated --- package-lock.json | 398 +++++++++++++++++++++++++++++++++++++++++++++++++----- package.json | 3 +- server.js | 65 +++++---- 3 files changed, 407 insertions(+), 59 deletions(-) diff --git a/package-lock.json b/package-lock.json index c684ff2..655685a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,32 +1,99 @@ { "name": "bogbook", - "version": "1.6.0", + "version": "1.7.0", "lockfileVersion": 1, "requires": true, "dependencies": { + "accepts": { + "version": "1.3.7", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", + "integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==", + "requires": { + "mime-types": "~2.1.24", + "negotiator": "0.6.2" + } + }, + "any-promise": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz", + "integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8=" + }, "async-limiter": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" }, - "charset": { + "cache-content-type": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/charset/-/charset-1.0.1.tgz", - "integrity": "sha512-6dVyOOYjpfFcL1Y4qChrAoQLRHvj2ziyhcm0QJlhOcAhykL/k1kTUPbeo+87MNRTRdk2OIIsIXbuF3x2wi5EXg==" - }, - "ecstatic": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/ecstatic/-/ecstatic-4.1.2.tgz", - "integrity": "sha512-lnrAOpU2f7Ra8dm1pW0D1ucyUxQIEk8RjFrvROg1YqCV0ueVu9hzgiSEbSyROqXDDiHREdqC4w3AwOTb23P4UQ==", - "requires": { - "charset": "^1.0.1", - "he": "^1.1.1", - "mime": "^2.4.1", - "minimist": "^1.1.0", - "on-finished": "^2.3.0", - "url-join": "^4.0.0" + "resolved": "https://registry.npmjs.org/cache-content-type/-/cache-content-type-1.0.1.tgz", + "integrity": "sha512-IKufZ1o4Ut42YUrZSo8+qnMTrFuKkvyoLXUywKz9GJ5BrhOFGhLdkx9sG4KAnVvbY6kEcSFjLQul+DVmBm2bgA==", + "requires": { + "mime-types": "^2.1.18", + "ylru": "^1.2.0" + } + }, + "co": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", + "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=" + }, + "content-disposition": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz", + "integrity": "sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==", + "requires": { + "safe-buffer": "5.1.2" + } + }, + "content-type": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", + "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" + }, + "cookies": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/cookies/-/cookies-0.8.0.tgz", + "integrity": "sha512-8aPsApQfebXnuI+537McwYsDtjVxGm8gTIzQI3FDW6t5t/DAhERxtnbEPN/8RX+uZthoz4eCOgloXaE5cYyNow==", + "requires": { + "depd": "~2.0.0", + "keygrip": "~1.1.0" + }, + "dependencies": { + "depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==" + } + } + }, + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "requires": { + "ms": "2.0.0" } }, + "deep-equal": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz", + "integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU=" + }, + "delegates": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", + "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=" + }, + "depd": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", + "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" + }, + "destroy": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", + "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" + }, "ed2curve": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/ed2curve/-/ed2curve-0.2.1.tgz", @@ -47,25 +114,187 @@ "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" }, - "he": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", - "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==" + "encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" + }, + "error-inject": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/error-inject/-/error-inject-1.0.0.tgz", + "integrity": "sha1-4rPZG1Su1nLzCdlQ0VSFD6EdTzc=" + }, + "escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" + }, + "fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" + }, + "http-assert": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/http-assert/-/http-assert-1.4.1.tgz", + "integrity": "sha512-rdw7q6GTlibqVVbXr0CKelfV5iY8G2HqEUkhSk297BMbSpSL8crXC+9rjKoMcZZEsksX30le6f/4ul4E28gegw==", + "requires": { + "deep-equal": "~1.0.1", + "http-errors": "~1.7.2" + } + }, + "http-errors": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.3.tgz", + "integrity": "sha512-ZTTX0MWrsQ2ZAhA1cejAwDLycFsd7I7nVtnkT3Ol0aqodaKW+0CTZDQ1uBv5whptCnc8e8HeRRJxRs0kmm/Qfw==", + "requires": { + "depd": "~1.1.2", + "inherits": "2.0.4", + "setprototypeof": "1.1.1", + "statuses": ">= 1.5.0 < 2", + "toidentifier": "1.0.0" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "is-generator-function": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.7.tgz", + "integrity": "sha512-YZc5EwyO4f2kWCax7oegfuSr9mFz1ZvieNYBEjmukLxgXfBUbxAWGVF7GZf0zidYtoBl3WvC07YK0wT76a+Rtw==" }, "is-wsl": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-1.1.0.tgz", "integrity": "sha1-HxbkqiKwTRM2tmGIpmrzxgDDpm0=" }, - "mime": { - "version": "2.4.4", - "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz", - "integrity": "sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA==" + "keygrip": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/keygrip/-/keygrip-1.1.0.tgz", + "integrity": "sha512-iYSchDJ+liQ8iwbSI2QqsQOvqv58eJCEanyJPJi+Khyu8smkcKSFUCbPwzFcL7YVtZ6eONjqRX/38caJ7QjRAQ==", + "requires": { + "tsscmp": "1.0.6" + } + }, + "koa": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/koa/-/koa-2.11.0.tgz", + "integrity": "sha512-EpR9dElBTDlaDgyhDMiLkXrPwp6ZqgAIBvhhmxQ9XN4TFgW+gEz6tkcsNI6BnUbUftrKDjVFj4lW2/J2aNBMMA==", + "requires": { + "accepts": "^1.3.5", + "cache-content-type": "^1.0.0", + "content-disposition": "~0.5.2", + "content-type": "^1.0.4", + "cookies": "~0.8.0", + "debug": "~3.1.0", + "delegates": "^1.0.0", + "depd": "^1.1.2", + "destroy": "^1.0.4", + "encodeurl": "^1.0.2", + "error-inject": "^1.0.0", + "escape-html": "^1.0.3", + "fresh": "~0.5.2", + "http-assert": "^1.3.0", + "http-errors": "^1.6.3", + "is-generator-function": "^1.0.7", + "koa-compose": "^4.1.0", + "koa-convert": "^1.2.0", + "on-finished": "^2.3.0", + "only": "~0.0.2", + "parseurl": "^1.3.2", + "statuses": "^1.5.0", + "type-is": "^1.6.16", + "vary": "^1.1.2" + } + }, + "koa-compose": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/koa-compose/-/koa-compose-4.1.0.tgz", + "integrity": "sha512-8ODW8TrDuMYvXRwra/Kh7/rJo9BtOfPc6qO8eAfC80CnCvSjSl0bkRM24X6/XBBEyj0v1nRUQ1LyOy3dbqOWXw==" }, - "minimist": { + "koa-convert": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" + "resolved": "https://registry.npmjs.org/koa-convert/-/koa-convert-1.2.0.tgz", + "integrity": "sha1-2kCHXfSd4FOQmNFwC1CCDOvNIdA=", + "requires": { + "co": "^4.6.0", + "koa-compose": "^3.0.0" + }, + "dependencies": { + "koa-compose": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/koa-compose/-/koa-compose-3.2.1.tgz", + "integrity": "sha1-qFzLQLfZhtjlo0Wzoazo6rz1Tec=", + "requires": { + "any-promise": "^1.1.0" + } + } + } + }, + "koa-send": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/koa-send/-/koa-send-5.0.0.tgz", + "integrity": "sha512-90ZotV7t0p3uN9sRwW2D484rAaKIsD8tAVtypw/aBU+ryfV+fR2xrcAwhI8Wl6WRkojLUs/cB9SBSCuIb+IanQ==", + "requires": { + "debug": "^3.1.0", + "http-errors": "^1.6.3", + "mz": "^2.7.0", + "resolve-path": "^1.4.0" + } + }, + "koa-static-server": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/koa-static-server/-/koa-static-server-1.4.0.tgz", + "integrity": "sha512-ZkGzD9+2OZubOL458GL8p7vEGfaneGGKSKIUJw9ftXzn36capQw3Wu5A//o7S10tQNgD1oYs96LGPtqtkcuXbQ==", + "requires": { + "koa-send": "^5.0.0", + "upath": "^1.0.2" + } + }, + "media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" + }, + "mime-db": { + "version": "1.42.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.42.0.tgz", + "integrity": "sha512-UbfJCR4UAVRNgMpfImz05smAXK7+c+ZntjaA26ANtkXLlOe947Aag5zdIcKQULAiF9Cq4WxBi9jUs5zkA84bYQ==" + }, + "mime-types": { + "version": "2.1.25", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.25.tgz", + "integrity": "sha512-5KhStqB5xpTAeGqKBAMgwaYMnQik7teQN4IAzC7npDv6kzeU6prfkR67bc87J1kWMPGkoaZSq1npmexMgkmEVg==", + "requires": { + "mime-db": "1.42.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "mz": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz", + "integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==", + "requires": { + "any-promise": "^1.0.0", + "object-assign": "^4.0.1", + "thenify-all": "^1.0.0" + } + }, + "negotiator": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", + "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" }, "on-finished": { "version": "2.3.0", @@ -75,6 +304,11 @@ "ee-first": "1.1.1" } }, + "only": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/only/-/only-0.0.2.tgz", + "integrity": "sha1-Kv3oTQPlC5qO3EROMGEKcCle37Q=" + }, "open": { "version": "6.4.0", "resolved": "https://registry.npmjs.org/open/-/open-6.4.0.tgz", @@ -83,6 +317,89 @@ "is-wsl": "^1.1.0" } }, + "parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, + "resolve-path": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/resolve-path/-/resolve-path-1.4.0.tgz", + "integrity": "sha1-xL2p9e+y/OZSR4c6s2u02DT+Fvc=", + "requires": { + "http-errors": "~1.6.2", + "path-is-absolute": "1.0.1" + }, + "dependencies": { + "http-errors": { + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", + "integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=", + "requires": { + "depd": "~1.1.2", + "inherits": "2.0.3", + "setprototypeof": "1.1.0", + "statuses": ">= 1.4.0 < 2" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "setprototypeof": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", + "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==" + } + } + }, + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, + "setprototypeof": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", + "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" + }, + "statuses": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", + "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" + }, + "thenify": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.0.tgz", + "integrity": "sha1-5p44obq+lpsBCCB5eLn2K4hgSDk=", + "requires": { + "any-promise": "^1.0.0" + } + }, + "thenify-all": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz", + "integrity": "sha1-GhkY1ALY/D+Y+/I02wvMjMEOlyY=", + "requires": { + "thenify": ">= 3.1.0 < 4" + } + }, + "toidentifier": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", + "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==" + }, + "tsscmp": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/tsscmp/-/tsscmp-1.0.6.tgz", + "integrity": "sha512-LxhtAkPDTkVCMQjt2h6eBVY28KCjikZqZfMcC15YBeNjkgUpdCfBu5HoiOTDu86v6smE8yOjyEktJ8hlbANHQA==" + }, "tweetnacl": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.1.tgz", @@ -93,10 +410,24 @@ "resolved": "https://registry.npmjs.org/tweetnacl-util/-/tweetnacl-util-0.15.0.tgz", "integrity": "sha1-RXbBzuXi1j0gf+5S8boCgZSAvHU=" }, - "url-join": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", - "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==" + "type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "requires": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + } + }, + "upath": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/upath/-/upath-1.2.0.tgz", + "integrity": "sha512-aZwGpamFO61g3OlfT7OQCHqhGnW43ieH9WZeP7QxN/G/jS4jfqUkZxoryvJgVPEcrl5NL/ggHsSmLMHuH64Lhg==" + }, + "vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" }, "ws": { "version": "6.2.1", @@ -105,6 +436,11 @@ "requires": { "async-limiter": "~1.0.0" } + }, + "ylru": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ylru/-/ylru-1.2.1.tgz", + "integrity": "sha512-faQrqNMzcPCHGVC2aaOINk13K+aaBDUPjGWl0teOXywElLjyVAB6Oe2jj62jHYtwsU49jXhScYbvPENK+6zAvQ==" } } } diff --git a/package.json b/package.json index c8799e4..ac7e569 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,9 @@ "author": "Ev Bogue ", "license": "MIT", "dependencies": { - "ecstatic": "^4.1.2", "ed2curve": "^0.2.1", + "koa": "^2.11.0", + "koa-static-server": "^1.4.0", "open": "^6.2.0", "tweetnacl": "^1.0.1", "tweetnacl-util": "^0.15.0", diff --git a/server.js b/server.js index 8f7d1c3..15d8802 100644 --- a/server.js +++ b/server.js @@ -1,11 +1,30 @@ -const HTTPPORT = 8089 -const WSPORT = 8080 -const URL = 'localhost' -const ADVERTISEMENTS = true +var fs = require('fs') +var homedir = require('os').homedir() + +var path = homedir + '/.bogbook/' +var bogdir = path + 'bogs/' +var addir = path + 'ads/' +var confpath = path + 'config.json' + +if (fs.existsSync(confpath)) { + console.log('loading config from ' + confpath) + var config = require(confpath) +} else { + var config = { + port: '8089', + wsport: '8080', + url: 'localhost', + ads: true, + author: '@Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0=' + } + config.fullurl = 'http://' + config.url + ':' + config.port + '/' + fs.writeFileSync(confpath, JSON.stringify(config), 'utf-8') +} -var ads = require('./ads') +console.log(config) -const fullURL = 'http://' + URL + ':' + HTTPPORT + '/' +if (!fs.existsSync(homedir + '/.bogbook/')) {fs.mkdirSync(homedir + '/.bogbook/')} +if (!fs.existsSync(bogdir)){fs.mkdirSync(bogdir)} if (process.argv[2] === 'verbose') { var VERBOSE = true @@ -14,7 +33,7 @@ if (process.argv[2] === 'verbose') { } console.log('Verbose output is ' + VERBOSE + ' run with `node server verbose` to see all output') -console.log('Advertisements are ' + ADVERTISEMENTS) +console.log('Advertisements are ' + config.ads) // log messages @@ -70,34 +89,26 @@ function printSendAd (msg, req) { // static server (8089) -var fs = require('fs') -var http = require('http') -var serve = require('ecstatic') +var serve = require('koa-static-server') +var koa = require('koa') var open = require('open') -http.createServer( - serve({ root: __dirname}) -).listen(HTTPPORT) +var app = new koa() -open(fullURL) +app.use(serve({rootDir: '.', notFoundFile: 'index.html'})) -console.log('Bogbook is running at: ' + fullURL) +app.listen(config.port) -// ws server (8080) +open(config.fullurl) + +console.log('Bogbook is running at: ' + config.fullurl) var bog = require('./bog') var WS = require('ws') var nacl = require('tweetnacl') nacl.util = require('tweetnacl-util') -var homedir = require('os').homedir() -var bogdir = homedir + '/.bogbook/bogs/' -var addir = homedir + '/.bogbook/ads/' - -if (!fs.existsSync(homedir + '/.bogbook/')) {fs.mkdirSync(homedir + '/.bogbook/')} -if (!fs.existsSync(bogdir)){fs.mkdirSync(bogdir)} - -var wserve = new WS.Server({ port: WSPORT }) +var wserve = new WS.Server({ port: config.wsport }) bog.keys().then(key => { wserve.on('connection', function (ws) { @@ -132,7 +143,7 @@ bog.keys().then(key => { bog.open(feed[0]).then(msg => { if (unboxedreq.seq === msg.seq) { printFeedIdentical(msg, req) - if (ADVERTISEMENTS) { + if (config.ads) { if (Math.floor(Math.random() * 4) == 2) { fs.readdir(addir, function (err, adfiles) { if (adfiles[0]) { @@ -141,12 +152,12 @@ bog.keys().then(key => { var obj = JSON.parse(adFile) var ad = { author: obj.author, - name: fullURL, + name: config.fullurl, content: obj.signature, timestamp: Date.now(), views: obj.views } - if ((obj.views > 100) && (obj.author != '@Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0=')) { + if ((obj.views > 100) && (obj.author != config.author)) { fs.unlinkSync(addir + obj.hash) //console.log('REMOVING AD') } else { -- cgit v1.2.3-70-g09d2 From 55989c498fd62a47b47cb033a764fd4dd23ed5a6 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Tue, 10 Dec 2019 12:45:48 -0600 Subject: only load more posts on profile and main feed pages (it was calling bottom of page everywhere and only displaying once you returned) --- views.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/views.js b/views.js index 9ec0af6..1f9aee3 100644 --- a/views.js +++ b/views.js @@ -92,13 +92,11 @@ function profilePage (src, keys) { addPosts(posts, keys).then(done => { index = index + 25 window.onscroll = function(ev) { - if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) { + if (((window.innerHeight + window.scrollY) >= document.body.scrollHeight) && (window.location.hash.substring(1) === src)) { posts = log.slice(index, index + 25) index = index + 25 - if (src === window.location.hash.substring(1)) { - addPosts(posts, keys) - } - //console.log("Bottom of page"); + addPosts(posts, keys) + console.log("Bottom of page") } } }) @@ -157,13 +155,11 @@ function publicPage (keys) { addPosts(posts, keys).then(done => { index = index + 25 window.onscroll = function(ev) { - if ((window.innerHeight + window.scrollY) >= document.body.scrollHeight) { + if (((window.innerHeight + window.scrollY) >= document.body.scrollHeight) && window.location.hash.substring(1) === '') { posts = log.slice(index, index + 25) index = index + 25 - if ('' === window.location.hash.substring(1)) { - addPosts(posts, keys) - } - //console.log("Bottom of page"); + addPosts(posts, keys) + console.log("Bottom of page") } } }) -- cgit v1.2.3-70-g09d2 From 0ce80cde9303db97124ada1a5745aed554041859 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 15 Dec 2019 08:40:05 -0600 Subject: fix some glitches with the edit function --- composer.js | 3 ++- render.js | 45 ++++++++++++++++++++++----------------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/composer.js b/composer.js index 5c46fce..9c1f236 100644 --- a/composer.js +++ b/composer.js @@ -54,8 +54,9 @@ function composer (keys, reply, gotName, edit) { if (edit) { console.log('APPENDING EDIT') var gotit = document.getElementById(reply.key) - gotit.appendChild(h('div', {classList: 'submessage'}, [render(msg, keys)])) + //gotit.appendChild(h('div', {classList: 'submessage'}, [render(msg, keys)])) var newContent = h('div', {innerHTML: marked(msg.text)}) + //console.log(gotit.childNodes.length) gotit.firstChild.replaceChild(newContent, gotit.firstChild.childNodes[1]) } if (reply) { diff --git a/render.js b/render.js index 27b8fb4..ca42e09 100644 --- a/render.js +++ b/render.js @@ -88,7 +88,7 @@ function render (msg, keys, preview) { if (msgcontents) { msgcontents.parentNode.replaceChild(editedcontents, msgcontents) } - message.appendChild(h('div', [ + message.firstChild.appendChild(h('div', [ 'edited in:', h('a', {href: '#' + nextPost.key}, [nextPost.key.substring(0, 10) + '...']) ])) @@ -123,7 +123,7 @@ function render (msg, keys, preview) { if (msg.type == 'edit') { message.appendChild(getHeader(msg, keys)) - message.appendChild(h('span', [ + message.firstChild.appendChild(h('span', [ 'edited: ', h('a', {href: '#' + msg.edited}, [msg.edited.substring(0, 10) + '...']) ])) @@ -157,35 +157,34 @@ function render (msg, keys, preview) { message.appendChild(getHeader(msg, keys)) if (msg.reply) { - message.appendChild(h('span', [ + //message.appendChild(h('span', [ + message.firstChild.appendChild(h('span', [ 're: ', h('a', {href: '#' + msg.reply}, [msg.reply.substring(0, 10) + '...']) ])) } - //quickName(msg.author).then(name => { - message.appendChild(h('div',{id: 'content:' + msg.key, innerHTML: marked(msg.text)})) - if (!preview) { + message.appendChild(h('div',{id: 'content:' + msg.key, innerHTML: marked(msg.text)})) + if (!preview) { + message.appendChild(h('button', { + onclick: function () { + quickName(msg.author).then(name => { + if (messageDiv.firstChild) { + messageDiv.insertBefore(h('div', {classList: 'submessage'}, [composer(keys, msg, name)]), messageDiv.childNodes[1]) + } else { + messageDiv.appendChild(h('div', {classList: 'submessage'}, [composer(keys, msg, name)])) + } + }) + } + }, ['Reply'])) + if (msg.author === keys.publicKey) { message.appendChild(h('button', { onclick: function () { - quickName(msg.author).then(name => { - if (messageDiv.firstChild) { - messageDiv.insertBefore(h('div', {classList: 'submessage'}, [composer(keys, msg, name)]), messageDiv.childNodes[1]) - } else { - messageDiv.appendChild(h('div', {classList: 'submessage'}, [composer(keys, msg, name)])) - } - }) + var editor = h('div', {classList: 'submessage'}, [composer(keys, msg, {name: false}, {edit: true})]) + messageDiv.appendChild(editor) } - }, ['Reply'])) - if (msg.author === keys.publicKey) { - message.appendChild(h('button', { - onclick: function () { - var editor = h('div', [composer(keys, msg, {name: false}, {edit: true})]) - message.appendChild(editor) - } - }, ['Edit'])) - } + }, ['Edit'])) } - //}) + } } else if (msg.type == 'name') { var mini = h('span', [' identified ', h('a', {href: '#' + msg.named }, [msg.named.substring(0, 10) + '...']), ' as ' + msg.name]) message.appendChild(getHeader(msg, keys, mini)) -- cgit v1.2.3-70-g09d2 From d8f46fdf6f93816edadab397c3d043ed85c2e359 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 15 Dec 2019 08:46:01 -0600 Subject: clean up --- render.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/render.js b/render.js index ca42e09..f8ce5fa 100644 --- a/render.js +++ b/render.js @@ -157,7 +157,6 @@ function render (msg, keys, preview) { message.appendChild(getHeader(msg, keys)) if (msg.reply) { - //message.appendChild(h('span', [ message.firstChild.appendChild(h('span', [ 're: ', h('a', {href: '#' + msg.reply}, [msg.reply.substring(0, 10) + '...']) @@ -168,10 +167,11 @@ function render (msg, keys, preview) { message.appendChild(h('button', { onclick: function () { quickName(msg.author).then(name => { + var compose = h('div', {classList: 'submessage'}, [composer(keys, msg, name)]) if (messageDiv.firstChild) { - messageDiv.insertBefore(h('div', {classList: 'submessage'}, [composer(keys, msg, name)]), messageDiv.childNodes[1]) + messageDiv.insertBefore(compose), messageDiv.childNodes[1]) } else { - messageDiv.appendChild(h('div', {classList: 'submessage'}, [composer(keys, msg, name)])) + messageDiv.appendChild(compose) } }) } -- cgit v1.2.3-70-g09d2 From d0d487baeec7f20cfe4fcfdfa583437c7ff43710 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 15 Dec 2019 09:00:36 -0600 Subject: adjust ad vs sync speed --- render.js | 2 +- server.js | 2 +- views.js | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/render.js b/render.js index f8ce5fa..00fb215 100644 --- a/render.js +++ b/render.js @@ -169,7 +169,7 @@ function render (msg, keys, preview) { quickName(msg.author).then(name => { var compose = h('div', {classList: 'submessage'}, [composer(keys, msg, name)]) if (messageDiv.firstChild) { - messageDiv.insertBefore(compose), messageDiv.childNodes[1]) + messageDiv.insertBefore(compose, messageDiv.childNodes[1]) } else { messageDiv.appendChild(compose) } diff --git a/server.js b/server.js index 15d8802..d324f43 100644 --- a/server.js +++ b/server.js @@ -144,7 +144,7 @@ bog.keys().then(key => { if (unboxedreq.seq === msg.seq) { printFeedIdentical(msg, req) if (config.ads) { - if (Math.floor(Math.random() * 4) == 2) { + if (Math.floor(Math.random() * 6) == 2) { fs.readdir(addir, function (err, adfiles) { if (adfiles[0]) { var num = Math.floor(Math.random() * (adfiles.length)) diff --git a/views.js b/views.js index 1f9aee3..b13d797 100644 --- a/views.js +++ b/views.js @@ -15,7 +15,7 @@ function profilePage (src, keys) { var subs = [src] - var interval = 1000 + var interval = 500 timer = function() { if (src === window.location.hash.substring(1)) { if (interval < 10000) { interval = interval + 100 } @@ -122,10 +122,10 @@ function searchPage (src, keys) { function publicPage (keys) { localforage.getItem('subscriptions').then(function (subs) { - var interval = 10000 + var interval = 1000 timer = function() { if ('' === window.location.hash.substring(1)) { - if (interval < 100000) { interval = interval + 1000 } + if (interval < 10000) { interval = interval + 1000 } sync(subs, keys) setTimeout(timer, interval) } -- cgit v1.2.3-70-g09d2 From 69c84ce6edaa3dd48f29b26eb39cbbb0ba07fb01 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 15 Dec 2019 14:48:00 -0600 Subject: add images to all posts --- css/style.css | 6 +++-- identify.js | 80 ++++++++++++++++++++++++++++++++++++++++------------------- render.js | 12 +++++++-- 3 files changed, 68 insertions(+), 30 deletions(-) diff --git a/css/style.css b/css/style.css index bdd1c6b..1683032 100644 --- a/css/style.css +++ b/css/style.css @@ -228,8 +228,10 @@ form.search { text-decoration: none; } -.profileAvatar { width: 75px; vertical-align: top; border-radius: 5px; margin-right: .25em; margin-bottom: .25em;} -.avatar { width: 25px; height: 25px; vertical-align: middle; border-radius: 5px; margin-right: .2em; } +.profileAvatar { width: 75px; vertical-align: top; border-radius: 5px; object-fit: cover; margin-right: .25em; margin-bottom: .25em;} +.avatar { width: 25px; height: 25px; vertical-align: middle; object-fit: cover; border-radius: 5px; margin-right: .2em; } + +.image { width: 75px; height: 75px; object-fit: cover; margin-right: .2em; border-radius: 5px;} button { display: inline-block; diff --git a/identify.js b/identify.js index 2ba5eea..1381c6f 100644 --- a/identify.js +++ b/identify.js @@ -2,7 +2,7 @@ function identify (src, profile, keys) { var identifyDiv = h('div') - if (src != keys.publicKey) { + if ((src[0] == '@') && (src != keys.publicKey)) { identifyDiv.appendChild(h('p', ['Please note: ' + src + ' is not you.'])) } @@ -14,8 +14,8 @@ function identify (src, profile, keys) { var canvas = document.getElementById("canvas") var ctx = canvas.getContext("2d") - var maxW = 250 - var maxH = 250 + var maxW + var maxH var input = document.getElementById('input') input.addEventListener('change', handleFiles) @@ -24,7 +24,23 @@ function identify (src, profile, keys) { var img = new Image img.onload = function() { var iw = img.width + console.log(iw) var ih = img.height + console.log(ih) + + if (iw > ih) { + maxW = 680 + maxH = 500 + } + if (iw < ih) { + maxW = 500 + maxH = 680 + } + if (iw == ih) { + maxW = 500 + maxH = 500 + } + var scale = Math.min((maxW/iw), (maxH/ih)) var iwScaled = iw*scale var ihScaled = ih*scale @@ -33,13 +49,11 @@ function identify (src, profile, keys) { ctx.drawImage(img, 0, 0, iwScaled, ihScaled) console.log(canvas.toDataURL('image/jpeg', 0.9)) photoURL.value = canvas.toDataURL('image/jpeg', 0.9) - //identifyDiv.appendChild(h('img', {src: photoURL.value})) } img.src = URL.createObjectURL(e.target.files[0]) } } }), - h('p', ['We recommend uploading a square photo. It will automatically be cropped to 250 x 250 px.']), h('canvas', {id: 'canvas', width: '0', height: '0'}), h('button', { onclick: function () { @@ -102,35 +116,49 @@ function identify (src, profile, keys) { }, ['Cancel']) ]) - var identifyButtons = h('span', [ - h('button', { + var identifyButtons = h('span') + + if (src[0] == '@') { + identifyButtons.appendChild(h('button', { onclick: function () { identifyDiv.appendChild(newName) identifyButtons.parentNode.removeChild(identifyButtons) } - }, ['Identify ' + src.substring(0, 10) + '... with a new name']), - h('button', { - onclick: function () { - identifyDiv.appendChild(newPhoto) - identifyButtons.parentNode.removeChild(identifyButtons) - } - }, ['Identify ' + src.substring(0, 10) + '... with a new photo']), - h('button', { - onclick: function () { - identifyDiv.appendChild(identifyButton) - identifyButtons.parentNode.removeChild(identifyButtons) - } - }, ['Cancel']) - ]) + }, ['New name'])) - var identifyButton = h('button', { + } + //}, ['Identify ' + src.substring(0, 10) + '... with a new name']), + identifyButtons.appendChild(h('button', { + onclick: function () { + identifyDiv.appendChild(newPhoto) + identifyButtons.parentNode.removeChild(identifyButtons) + } + }, ['New image'])) + //}, ['Identify ' + src.substring(0, 10) + '... with a new photo']), + identifyButtons.appendChild(h('button', { onclick: function () { - profile.appendChild(identifyDiv) - profile.appendChild(identifyButtons) - identifyButton.parentNode.removeChild(identifyButton) + identifyDiv.appendChild(identifyButton) + identifyButtons.parentNode.removeChild(identifyButtons) } - },['Identify ' + src.substring(0, 10) + '...']) + }, ['Cancel'])) + if (src[0] == '@') { + var identifyButton = h('button', { + onclick: function () { + profile.appendChild(identifyDiv) + profile.appendChild(identifyButtons) + identifyButton.parentNode.removeChild(identifyButton) + } + }, ['Identify ' + src.substring(0, 10) + '...']) + } else { + var identifyButton = h('button', { + onclick: function () { + profile.appendChild(identifyDiv) + profile.appendChild(identifyButtons) + identifyButton.parentNode.removeChild(identifyButton) + } + }, ['Add to ' + src.substring(0, 10) + '...']) + } return identifyButton } diff --git a/render.js b/render.js index 00fb215..5070a5f 100644 --- a/render.js +++ b/render.js @@ -102,6 +102,10 @@ function render (msg, keys, preview) { if (!messageExists) { messageDiv.appendChild(h('div', {classList: 'submessage'}, [render(nextPost, keys)])) } + } + + if (nextPost.imaged == msg.key) { + message.insertBefore(h('img', {src: nextPost.image, classList: 'image'}), message.childNodes[message.childNodes.length - 1]) } }) } @@ -163,8 +167,9 @@ function render (msg, keys, preview) { ])) } message.appendChild(h('div',{id: 'content:' + msg.key, innerHTML: marked(msg.text)})) + var buttons = h('div') if (!preview) { - message.appendChild(h('button', { + buttons.appendChild(h('button', { onclick: function () { quickName(msg.author).then(name => { var compose = h('div', {classList: 'submessage'}, [composer(keys, msg, name)]) @@ -177,13 +182,16 @@ function render (msg, keys, preview) { } }, ['Reply'])) if (msg.author === keys.publicKey) { - message.appendChild(h('button', { + buttons.appendChild(h('button', { onclick: function () { var editor = h('div', {classList: 'submessage'}, [composer(keys, msg, {name: false}, {edit: true})]) messageDiv.appendChild(editor) } }, ['Edit'])) + buttons.appendChild(identify(msg.key, message, keys)) } + + message.appendChild(buttons) } } else if (msg.type == 'name') { var mini = h('span', [' identified ', h('a', {href: '#' + msg.named }, [msg.named.substring(0, 10) + '...']), ' as ' + msg.name]) -- cgit v1.2.3-70-g09d2 From 96af07d8be5ee32a546de4c4ffd64e5180768cae Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 15 Dec 2019 16:08:35 -0600 Subject: click to expand images --- css/style.css | 6 +++++- render.js | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/css/style.css b/css/style.css index 1683032..7593324 100644 --- a/css/style.css +++ b/css/style.css @@ -231,7 +231,11 @@ form.search { .profileAvatar { width: 75px; vertical-align: top; border-radius: 5px; object-fit: cover; margin-right: .25em; margin-bottom: .25em;} .avatar { width: 25px; height: 25px; vertical-align: middle; object-fit: cover; border-radius: 5px; margin-right: .2em; } -.image { width: 75px; height: 75px; object-fit: cover; margin-right: .2em; border-radius: 5px;} +.image { width: 75px; height: 75px; object-fit: cover; margin-right: .2em; border-radius: 5px; cursor: pointer;} + +#viewer {position: fixed; left: 2em; top: 3em; background: white; padding: .5em; border: 1px solid #ddd; border-radius: 5px;} + +#viewer img { border-radius: 5px; margin-left: auto; margin-right: auto; cursor: pointer;} button { display: inline-block; diff --git a/render.js b/render.js index 5070a5f..d85d04b 100644 --- a/render.js +++ b/render.js @@ -105,7 +105,24 @@ function render (msg, keys, preview) { } if (nextPost.imaged == msg.key) { - message.insertBefore(h('img', {src: nextPost.image, classList: 'image'}), message.childNodes[message.childNodes.length - 1]) + + var img = h('img', { + src: nextPost.image, + classList: 'image', + onclick: function () { + var viewimg = h('div', {id: 'viewer', onclick: function () { + var viewer = document.getElementById('viewer') + viewer.parentNode.removeChild(viewer) + }}, [ + h('img', { + src: nextPost.image + }) + ]) + document.body.appendChild(viewimg) + } + }) + + message.insertBefore(img, message.childNodes[message.childNodes.length - 1]) } }) } -- cgit v1.2.3-70-g09d2 From 6a19e648f27efde551b7f5902c4b72f61e048cb4 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 15 Dec 2019 16:10:16 -0600 Subject: fade viewer in --- css/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css/style.css b/css/style.css index 7593324..2a7745b 100644 --- a/css/style.css +++ b/css/style.css @@ -66,7 +66,7 @@ hr { #scroller:last-child { margin-bottom: 10em; } -.message, .message > *, .navbar, .navbar > *, #ad, #ad > * { +.message, .message > *, .navbar, .navbar > *, #ad, #ad > *, #viewer > * { animation: fadein .5s; } -- cgit v1.2.3-70-g09d2 From 3fe02c91174d7316ae2c66a7679ab807ca43c6c3 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 21 Dec 2019 14:26:30 -0600 Subject: initial stab at private beacons --- app.js | 3 ++ beacons.js | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ css/style.css | 4 +-- gossip.js | 3 ++ index.html | 1 + render.js | 73 +++++++++++++++++++++++++++++++++--------------- server.js | 59 +++++++++++++++++++++++++++------------ settings.js | 49 -------------------------------- 8 files changed, 190 insertions(+), 91 deletions(-) create mode 100644 beacons.js diff --git a/app.js b/app.js index 7fe1ae2..5dd49a5 100644 --- a/app.js +++ b/app.js @@ -10,6 +10,8 @@ function route (keys) { if (src === 'settings') { settingsPage(keys) + } else if (src === 'beacons') { + beaconsPage(keys) } else if (src[0] === '@') { profilePage(src, keys) } else if (src[0] === '?') { @@ -28,6 +30,7 @@ keys().then(key => { h('div', {classList: 'internal'}, [ h('li', [h('a', {href: '#'}, ['Home'])]), h('li', [h('a', {href: '#' + key.publicKey}, [getName(key.publicKey, keys)])]), + h('li', [h('a', {href: '#beacons'}, ['Beacons'])]), h('li', {classList: 'right'}, [h('a', {href: '#settings'}, ['Settings'])]), h('form', { classList: 'search', onsubmit: function (e) { diff --git a/beacons.js b/beacons.js new file mode 100644 index 0000000..1656879 --- /dev/null +++ b/beacons.js @@ -0,0 +1,89 @@ + +function beaconsPage (keys) { + + var pubslist = h('select') + + localforage.getItem('securepubs').then(function (servers) { + servers.forEach(function (pub) { + pubslist.appendChild( + h('option', {value: pub}, [pub]) + ) + }) + }) + + var ads = h('div', {classList: 'message'}) + + ads.appendChild(h('span', {innerHTML: marked('Sometimes when you\'re lost on the Internet you might want to send out a beacon so that people can see you. \n\n Beacons from guests will run for 100 views before they are deleted by the pub. \n\nSelect a pub:')})) + + ads.appendChild(pubslist) + + var recp = h('input', {placeholder: 'Ex: @Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0='}) + + var adstext = h('textarea', {placeholder: 'Hello World!'}) + + ads.appendChild(h('span', [ + h('br'), + h('p', [" Send a beacon (leave the 'To:' field blank for a public beacon): "]), + h('p', ['To: ', + recp + ]), + adstext, + h('br'), + h('button', { + onclick: function () { + var split = pubslist.value.split('~') + console.log(split) + var serverurl = split[0] + var serverpub = split[1] + var ws = new WebSocket(serverurl) + + if ((recp.value) && (adstext.value)) { + var tobox = { + author: keys.publicKey, + timestamp: Date.now(), + content: adstext.value + } + box(JSON.stringify(tobox), recp.value, keys).then(boxedmsg => { + var msg = { + type: 'beacon', + author: keys.publicKey, + box: boxedmsg + } + ws.onopen = function () { + box(JSON.stringify(msg), serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) + adstext.value = '' + recp.value = '' + } + }) + } + + if ((!recp.value) && (adstext.value)) { + var msg = { + type: 'beacon', + author: keys.publicKey + } + msg.signature = nacl.util.encodeBase64(nacl.sign(nacl.util.decodeUTF8(JSON.stringify(adstext.value)), nacl.util.decodeBase64(keys.privateKey))) + ws.onopen = function () { + box(JSON.stringify(msg), serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) + adstext.value = '' + } + } + } + }, ['Publish']) + ])) + + scroller.appendChild(ads) +} + diff --git a/css/style.css b/css/style.css index 2a7745b..1eef78f 100644 --- a/css/style.css +++ b/css/style.css @@ -70,7 +70,7 @@ hr { animation: fadein .5s; } -#ad { +#ad, #pm { background: white; font-size: .8em; border: 1px solid #ddd; @@ -82,7 +82,7 @@ hr { width: 250px; } -#ad button { +#ad button, #pm button { font-size: .8em; margin: 0; padding: 0; diff --git a/gossip.js b/gossip.js index d0b91f1..3f88b54 100644 --- a/gossip.js +++ b/gossip.js @@ -53,6 +53,9 @@ function sync (subs, keys) { unboxedreq.signature = unboxedreq.content renderAd(unboxedreq) } + if (unboxedreq.box) { + renderAd(unboxedreq, keys) + } if (unboxedreq.seq === 0) { var stringedfeed = JSON.stringify(srclog) box(stringedfeed, serverpub, keys).then(boxed => { diff --git a/index.html b/index.html index 0396bcc..5d18890 100644 --- a/index.html +++ b/index.html @@ -17,6 +17,7 @@ + diff --git a/render.js b/render.js index d85d04b..02e4b88 100644 --- a/render.js +++ b/render.js @@ -1,4 +1,6 @@ -function renderAd (ad) { +function renderAd (ad, keys) { + console.log(ad) + var screen = document.getElementById('screen') var adspot = document.getElementById('ad') @@ -11,30 +13,57 @@ function renderAd (ad) { if (ad.views) { adspace.appendChild(h('span', {classList: 'right'}, [h('pre', [ad.views + ' views'])])) } else { - adspace.appendChild(h('span', {classList: 'right'}, [h('pre', ['ad'])])) + adspace.appendChild(h('span', {classList: 'right'}, [h('pre', ['beacon'])])) } - open(ad).then(opened => { - quickName(ad.author).then(gotName => { - newAd = h('div', {id: 'ad'}, [ - adspace, - h('p', {innerHTML: marked(opened)}), - h('button', {classList: 'right', - onclick: function () { - adspot = document.getElementById('ad') - adspot.parentNode.removeChild(adspot) - } - }, ['Heard']), - h('span', [ - '—', - h('a', {href: '#' + ad.author}, [gotName]), - ' from ', - h('a', {href: ad.name}, [ad.name]) + if (ad.box) { + unbox(ad.box, ad.author, keys).then(unboxed => { + var msg = JSON.parse(nacl.util.encodeUTF8(unboxed)) + quickName(ad.author).then(gotName => { + beacon = h('div', {id: 'pm'}, [ + h('span', {classList: 'right'}, [h('pre', [human(new Date(msg.timestamp))])]), + h('p', {innerHTML: marked(msg.content)}), + h('button', {classList: 'right', + onclick: function () { + pmspot = document.getElementById('pm') + pmspot.parentNode.removeChild(pmspot) + } + }, ['Heard']), + h('span', [ + '—', + h('a', {href: '#' + ad.author}, [gotName]), + ' from ', + h('a', {href: ad.name}, [ad.name]) + ]) ]) - ]) - screen.appendChild(newAd) - }) - }) + screen.append(beacon) + }) + }) + } + + if (ad.signature) { + open(ad).then(opened => { + quickName(ad.author).then(gotName => { + newAd = h('div', {id: 'ad'}, [ + adspace, + h('p', {innerHTML: marked(opened)}), + h('button', {classList: 'right', + onclick: function () { + adspot = document.getElementById('ad') + adspot.parentNode.removeChild(adspot) + } + }, ['Heard']), + h('span', [ + '—', + h('a', {href: '#' + ad.author}, [gotName]), + ' from ', + h('a', {href: ad.name}, [ad.name]) + ]) + ]) + screen.appendChild(newAd) + }) + }) + } } function getHeader (post, keys, mini) { diff --git a/server.js b/server.js index d324f43..5ad7064 100644 --- a/server.js +++ b/server.js @@ -119,15 +119,27 @@ bog.keys().then(key => { } else { bog.unbox(req.box, req.requester, key).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - if (unboxedreq.type == 'ad') { - - var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.signature))).toString('hex') - - var obj = { - hash: hex, - author: unboxedreq.author, - signature: unboxedreq.signature, - views: 0 + //console.log(unboxedreq) + if (unboxedreq.type == 'beacon') { + if (unboxedreq.box) { + var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.box))).toString('hex') + + var obj = { + hash: hex, + author: unboxedreq.author, + box: unboxedreq.box, + views: 0 + } + } + + if (unboxedreq.signature) { + var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.signature))).toString('hex') + var obj = { + hash: hex, + author: unboxedreq.author, + signature: unboxedreq.signature, + views: 0 + } } fs.writeFile(addir + hex, JSON.stringify(obj), 'UTF-8', function () { @@ -150,13 +162,25 @@ bog.keys().then(key => { var num = Math.floor(Math.random() * (adfiles.length)) fs.readFile(addir + adfiles[num], 'UTF-8', function (err, adFile) { var obj = JSON.parse(adFile) - var ad = { - author: obj.author, - name: config.fullurl, - content: obj.signature, - timestamp: Date.now(), - views: obj.views + + if (obj.signature) { + var ad = { + author: obj.author, + name: config.fullurl, + content: obj.signature, + views: obj.views + } } + + if (obj.box) { + var ad = { + author: obj.author, + name: config.fullurl, + box: obj.box, + views: obj.views + } + } + if ((obj.views > 100) && (obj.author != config.author)) { fs.unlinkSync(addir + obj.hash) //console.log('REMOVING AD') @@ -165,6 +189,7 @@ bog.keys().then(key => { fs.writeFileSync(addir + obj.hash, JSON.stringify(obj), 'UTF-8') } printSendAd(ad, req) + console.log(ad) //console.log('SENDING AD') bog.box(JSON.stringify(ad), req.requester, key).then(boxed => { sendobj = { @@ -175,9 +200,7 @@ bog.keys().then(key => { ws.close() }) }) - } else { - ads.make('Hello World.') - } + } }) } } diff --git a/settings.js b/settings.js index 51dc1f2..c88ea07 100644 --- a/settings.js +++ b/settings.js @@ -56,11 +56,7 @@ function settingsPage (keys) { var add = h('input', {placeholder: 'Add a pub'}) - var pubslist = h('select') - localforage.getItem('securepubs').then(function (servers) { - - pubs.appendChild(h('div', [ add, h('button', { @@ -74,9 +70,6 @@ function settingsPage (keys) { ])) servers.forEach(function (pub) { - pubslist.appendChild( - h('option', {value: pub}, [pub]) - ) pubs.appendChild(h('p', [ pub, h('button', { @@ -98,52 +91,10 @@ function settingsPage (keys) { } }, ['Reset pubs'])) - var ads = h('div', {classList: 'message'}) - - - ads.appendChild(h('span', {innerHTML: marked('Submit an advertisement. Right now advertisements are free for anyone to post to this pub. Ads from guests will run for 100 views before they are deleted by the pub. \n\nSelect a pub:')})) - - ads.appendChild(pubslist) - - var adstext = h('input', {placeholder: 'Hello World!'}) - - ads.appendChild(h('span', [ - h('br'), - ' Write an ad: ', - h('br'), - adstext, - h('button', { - onclick: function () { - var split = pubslist.value.split('~') - console.log(split) - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) - - var msg = { - type: 'ad', - author: keys.publicKey - } - msg.signature = nacl.util.encodeBase64(nacl.sign(nacl.util.decodeUTF8(JSON.stringify(adstext.value)), nacl.util.decodeBase64(keys.privateKey))) - ws.onopen = function () { - box(JSON.stringify(msg), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - adstext.value = '' - } - }, ['Publish']) - ])) - scroller.appendChild(welcome) scroller.appendChild(keyDiv) scroller.appendChild(pubs) scroller.appendChild(everything) //scroller.appendChild(regenerate) - scroller.appendChild(ads) } -- cgit v1.2.3-70-g09d2 From 6473d912e9bed93a80641950f451a184f17b390c Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 21 Dec 2019 14:47:31 -0600 Subject: remove console.log --- server.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server.js b/server.js index 5ad7064..3ec7f5d 100644 --- a/server.js +++ b/server.js @@ -189,7 +189,6 @@ bog.keys().then(key => { fs.writeFileSync(addir + obj.hash, JSON.stringify(obj), 'UTF-8') } printSendAd(ad, req) - console.log(ad) //console.log('SENDING AD') bog.box(JSON.stringify(ad), req.requester, key).then(boxed => { sendobj = { -- cgit v1.2.3-70-g09d2 From 07ad37b0fd4711da999a5caddc7e04c4e569110f Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 22 Dec 2019 08:51:10 -0600 Subject: this should prevent arriving posts from rendering on incorrect views --- gossip.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gossip.js b/gossip.js index 3f88b54..eb0812e 100644 --- a/gossip.js +++ b/gossip.js @@ -110,7 +110,13 @@ function sync (subs, keys) { open(unboxedreq[i]).then(opened => { log.unshift(opened) var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + + var src = window.location.hash.substring(1) + console.log(src) + if ((src === sub) || (src === '')) { + var scroller = document.getElementById('scroller') + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + } if (unboxedreq.length + lastmsg.seq === opened.seq) { log.sort((a, b) => a.timestamp - b.timestamp) var reversed = log.reverse() @@ -162,8 +168,12 @@ function sync (subs, keys) { for (var i = unboxedreq.length -1; i >= 0; --i) { open(unboxedreq[i]).then(opened => { log.unshift(opened) - var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + var src = window.location.hash.substring(1) + console.log(src) + if ((src === sub) || (src === '')) { + var scroller = document.getElementById('scroller') + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + } if (opened.seq === unboxedreq.length) { log.sort((a, b) => a.timestamp - b.timestamp) var reversed = log.reverse() -- cgit v1.2.3-70-g09d2 From 05c2f99b722ad72be856f1c5072fe1db6a614f9d Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 22 Dec 2019 09:16:11 -0600 Subject: fix error where previous is undefined --- render.js | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/render.js b/render.js index 02e4b88..3979bb3 100644 --- a/render.js +++ b/render.js @@ -182,24 +182,26 @@ function render (msg, keys, preview) { message.appendChild(contents) get(msg.edited).then(previous => { - fragment = document.createDocumentFragment() - var diff = JsDiff.diffWords(previous.text, msg.text) - diff.forEach(function (part) { - if (part.added === true) { - color = 'blue' - } else if (part.removed === true) { - color = 'gray' - } else {color = '#333'} - var span = h('span') - span.style.color = color - if (part.removed === true) { - span.appendChild(h('del', document.createTextNode(part.value))) - } else { - span.appendChild(document.createTextNode(part.value)) - } - fragment.appendChild(span) - }) - contents.appendChild(h('code', [fragment])) + if (previous) { + fragment = document.createDocumentFragment() + var diff = JsDiff.diffWords(previous.text, msg.text) + diff.forEach(function (part) { + if (part.added === true) { + color = 'blue' + } else if (part.removed === true) { + color = 'gray' + } else {color = '#333'} + var span = h('span') + span.style.color = color + if (part.removed === true) { + span.appendChild(h('del', document.createTextNode(part.value))) + } else { + span.appendChild(document.createTextNode(part.value)) + } + fragment.appendChild(span) + }) + contents.appendChild(h('code', [fragment])) + } }) } -- cgit v1.2.3-70-g09d2 From 8a030de9eb5ca256be397311efbf58872120ec17 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 22 Dec 2019 09:17:24 -0600 Subject: remove console logs --- gossip.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/gossip.js b/gossip.js index eb0812e..2636ac6 100644 --- a/gossip.js +++ b/gossip.js @@ -112,7 +112,6 @@ function sync (subs, keys) { var scroller = document.getElementById('scroller') var src = window.location.hash.substring(1) - console.log(src) if ((src === sub) || (src === '')) { var scroller = document.getElementById('scroller') scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) @@ -169,7 +168,6 @@ function sync (subs, keys) { open(unboxedreq[i]).then(opened => { log.unshift(opened) var src = window.location.hash.substring(1) - console.log(src) if ((src === sub) || (src === '')) { var scroller = document.getElementById('scroller') scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) -- cgit v1.2.3-70-g09d2 From b9a1917fdbc5d79d58b4c7b9e268d555e97624ca Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 22 Dec 2019 12:38:19 -0600 Subject: make beacons go away with the heard button, also broadcast a heard to the pub --- beacons.js | 1 - gossip.js | 2 +- render.js | 192 ++++++++++++++++++++++++++++++++++++++++++------------------- server.js | 4 ++ 4 files changed, 138 insertions(+), 61 deletions(-) diff --git a/beacons.js b/beacons.js index 1656879..79f88a5 100644 --- a/beacons.js +++ b/beacons.js @@ -1,4 +1,3 @@ - function beaconsPage (keys) { var pubslist = h('select') diff --git a/gossip.js b/gossip.js index 2636ac6..0c12a40 100644 --- a/gossip.js +++ b/gossip.js @@ -51,7 +51,7 @@ function sync (subs, keys) { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) if (unboxedreq.content) { unboxedreq.signature = unboxedreq.content - renderAd(unboxedreq) + renderAd(unboxedreq, keys) } if (unboxedreq.box) { renderAd(unboxedreq, keys) diff --git a/render.js b/render.js index 3979bb3..8e90a84 100644 --- a/render.js +++ b/render.js @@ -1,69 +1,143 @@ function renderAd (ad, keys) { - console.log(ad) + localforage.getItem(ad.hash).then(heard => { + if (!heard) { + var screen = document.getElementById('screen') + var adspot = document.getElementById('ad') + var pmspot = document.getElementById('pm') - var screen = document.getElementById('screen') - var adspot = document.getElementById('ad') + if (adspot) { + adspot.parentNode.removeChild(adspot) + } - if (adspot) { - adspot.parentNode.removeChild(adspot) - } + if (pmspot) { + pmspot.parentNode.removeChild(pmspot) + } - var adspace = h('span') + var adspace = h('span') - if (ad.views) { - adspace.appendChild(h('span', {classList: 'right'}, [h('pre', [ad.views + ' views'])])) - } else { - adspace.appendChild(h('span', {classList: 'right'}, [h('pre', ['beacon'])])) - } + if (ad.views) { + adspace.appendChild(h('span', {classList: 'right'}, [h('pre', [ad.views + ' views'])])) + } else { + adspace.appendChild(h('span', {classList: 'right'}, [h('pre', ['beacon'])])) + } - if (ad.box) { - unbox(ad.box, ad.author, keys).then(unboxed => { - var msg = JSON.parse(nacl.util.encodeUTF8(unboxed)) - quickName(ad.author).then(gotName => { - beacon = h('div', {id: 'pm'}, [ - h('span', {classList: 'right'}, [h('pre', [human(new Date(msg.timestamp))])]), - h('p', {innerHTML: marked(msg.content)}), - h('button', {classList: 'right', - onclick: function () { - pmspot = document.getElementById('pm') - pmspot.parentNode.removeChild(pmspot) - } - }, ['Heard']), - h('span', [ - '—', - h('a', {href: '#' + ad.author}, [gotName]), - ' from ', - h('a', {href: ad.name}, [ad.name]) - ]) - ]) - screen.append(beacon) - }) - }) - } + if (ad.box) { + unbox(ad.box, ad.author, keys).then(unboxed => { + var msg = JSON.parse(nacl.util.encodeUTF8(unboxed)) + quickName(ad.author).then(gotName => { + beacon = h('div', {id: 'pm'}, [ + h('span', {classList: 'right'}, [h('pre', [human(new Date(msg.timestamp))])]), + h('p', {innerHTML: marked(msg.content)}), + h('button', {classList: 'right', + onclick: function () { + pmspot = document.getElementById('pm') + pmspot.parentNode.removeChild(pmspot) + if (msg.content.substring((msg.content.length - 6), msg.content.length) === 'Heard.') { + localforage.setItem(ad.hash, true).then(success => { + //console.log('heard: ' + ad.hash) + }) - if (ad.signature) { - open(ad).then(opened => { - quickName(ad.author).then(gotName => { - newAd = h('div', {id: 'ad'}, [ - adspace, - h('p', {innerHTML: marked(opened)}), - h('button', {classList: 'right', - onclick: function () { - adspot = document.getElementById('ad') - adspot.parentNode.removeChild(adspot) - } - }, ['Heard']), - h('span', [ - '—', - h('a', {href: '#' + ad.author}, [gotName]), - ' from ', - h('a', {href: ad.name}, [ad.name]) - ]) - ]) - screen.appendChild(newAd) - }) - }) - } + } else { + var split = ad.pub.split('~') + var serverurl = split[0] + var serverpub = split[1] + var ws = new WebSocket(serverurl) + + var tobox = { + author: keys.publicKey, + timestamp: Date.now(), + content: '>' + msg.content + '\n\nHeard.' + } + + box(JSON.stringify(tobox), ad.author, keys).then(boxedmsg => { + var msg = { + type: 'beacon', + author: keys.publicKey, + box: boxedmsg + } + ws.onopen = function () { + box(JSON.stringify(msg), serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + localforage.setItem(ad.hash, true).then(success => { + //console.log('heard: ' + ad.hash) + }) + }) + } + }) + } + } + }, ['Heard']), + h('span', [ + '—', + h('a', {href: '#' + ad.author}, [gotName]), + ' from ', + h('a', {href: ad.name}, [ad.name]) + ]) + ]) + screen.append(beacon) + }) + }) + } + + if (ad.signature) { + open(ad).then(opened => { + quickName(ad.author).then(gotName => { + newAd = h('div', {id: 'ad'}, [ + adspace, + h('p', {innerHTML: marked(opened)}), + h('button', {classList: 'right', + onclick: function () { + adspot = document.getElementById('ad') + adspot.parentNode.removeChild(adspot) + var split = ad.pub.split('~') + var serverurl = split[0] + var serverpub = split[1] + var ws = new WebSocket(serverurl) + + + + var tobox = { + author: keys.publicKey, + timestamp: Date.now(), + content: '>' + opened + '\n\nHeard.' + } + + box(JSON.stringify(tobox), ad.author, keys).then(boxedmsg => { + var msg = { + type: 'beacon', + author: keys.publicKey, + box: boxedmsg + } + ws.onopen = function () { + box(JSON.stringify(msg), serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + localforage.setItem(ad.hash, true).then(success => {console.log('heard: ' + ad.hash)}) + }) + } + }) + } + }, ['Heard']), + h('span', [ + '—', + h('a', {href: '#' + ad.author}, [gotName]), + ' from ', + h('a', {href: ad.name}, [ad.name]) + ]) + ]) + screen.appendChild(newAd) + }) + }) + } + } + }) } function getHeader (post, keys, mini) { diff --git a/server.js b/server.js index 3ec7f5d..e47f165 100644 --- a/server.js +++ b/server.js @@ -166,7 +166,9 @@ bog.keys().then(key => { if (obj.signature) { var ad = { author: obj.author, + hash: obj.hash, name: config.fullurl, + pub: 'ws://' + config.url + ':' + config.wsport + '/~' + key.publicKey, content: obj.signature, views: obj.views } @@ -175,7 +177,9 @@ bog.keys().then(key => { if (obj.box) { var ad = { author: obj.author, + hash: obj.hash, name: config.fullurl, + pub: 'ws://' + config.url + ':' + config.wsport + '/~' + key.publicKey, box: obj.box, views: obj.views } -- cgit v1.2.3-70-g09d2 From e8b76b2b33de8bbe053422d5e679a4d425e67b8e Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 22 Dec 2019 13:27:05 -0600 Subject: unboxable messages were removing beacon box --- render.js | 110 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/render.js b/render.js index 8e90a84..97798e6 100644 --- a/render.js +++ b/render.js @@ -9,9 +9,6 @@ function renderAd (ad, keys) { adspot.parentNode.removeChild(adspot) } - if (pmspot) { - pmspot.parentNode.removeChild(pmspot) - } var adspace = h('span') @@ -23,63 +20,68 @@ function renderAd (ad, keys) { if (ad.box) { unbox(ad.box, ad.author, keys).then(unboxed => { - var msg = JSON.parse(nacl.util.encodeUTF8(unboxed)) - quickName(ad.author).then(gotName => { - beacon = h('div', {id: 'pm'}, [ - h('span', {classList: 'right'}, [h('pre', [human(new Date(msg.timestamp))])]), - h('p', {innerHTML: marked(msg.content)}), - h('button', {classList: 'right', - onclick: function () { - pmspot = document.getElementById('pm') - pmspot.parentNode.removeChild(pmspot) - if (msg.content.substring((msg.content.length - 6), msg.content.length) === 'Heard.') { - localforage.setItem(ad.hash, true).then(success => { - //console.log('heard: ' + ad.hash) - }) - - } else { - var split = ad.pub.split('~') - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) - - var tobox = { - author: keys.publicKey, - timestamp: Date.now(), - content: '>' + msg.content + '\n\nHeard.' - } + if (unboxed) { + var msg = JSON.parse(nacl.util.encodeUTF8(unboxed)) + if (pmspot) { + pmspot.parentNode.removeChild(pmspot) + } + quickName(ad.author).then(gotName => { + beacon = h('div', {id: 'pm'}, [ + h('span', {classList: 'right'}, [h('pre', [human(new Date(msg.timestamp))])]), + h('p', {innerHTML: marked(msg.content)}), + h('button', {classList: 'right', + onclick: function () { + pmspot = document.getElementById('pm') + pmspot.parentNode.removeChild(pmspot) + if (msg.content.substring((msg.content.length - 6), msg.content.length) === 'Heard.') { + localforage.setItem(ad.hash, true).then(success => { + //console.log('heard: ' + ad.hash) + }) + + } else { + var split = ad.pub.split('~') + var serverurl = split[0] + var serverpub = split[1] + var ws = new WebSocket(serverurl) - box(JSON.stringify(tobox), ad.author, keys).then(boxedmsg => { - var msg = { - type: 'beacon', + var tobox = { author: keys.publicKey, - box: boxedmsg + timestamp: Date.now(), + content: '>' + msg.content + '\n\nHeard.' } - ws.onopen = function () { - box(JSON.stringify(msg), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - localforage.setItem(ad.hash, true).then(success => { - //console.log('heard: ' + ad.hash) + + box(JSON.stringify(tobox), ad.author, keys).then(boxedmsg => { + var msg = { + type: 'beacon', + author: keys.publicKey, + box: boxedmsg + } + ws.onopen = function () { + box(JSON.stringify(msg), serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + localforage.setItem(ad.hash, true).then(success => { + //console.log('heard: ' + ad.hash) + }) }) - }) - } - }) + } + }) + } } - } - }, ['Heard']), - h('span', [ - '—', - h('a', {href: '#' + ad.author}, [gotName]), - ' from ', - h('a', {href: ad.name}, [ad.name]) + }, ['Heard']), + h('span', [ + '—', + h('a', {href: '#' + ad.author}, [gotName]), + ' from ', + h('a', {href: ad.name}, [ad.name]) + ]) ]) - ]) - screen.append(beacon) - }) + screen.append(beacon) + }) + } }) } -- cgit v1.2.3-70-g09d2 From 047b88d8deb5b4338b4162f519de7ef570d98ae2 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 22 Dec 2019 13:52:53 -0600 Subject: put pms on the right --- css/style.css | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/css/style.css b/css/style.css index 1eef78f..6e26838 100644 --- a/css/style.css +++ b/css/style.css @@ -78,10 +78,17 @@ hr { position: fixed; padding: .3em .5em; bottom: 5px; - left: 5px; width: 250px; } +#ad { + left: 5px; +} + +#pm { + right: 5px; +} + #ad button, #pm button { font-size: .8em; margin: 0; -- cgit v1.2.3-70-g09d2 From 7b410ab4c605928ce72d9c07f4784954999d9dda Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Thu, 26 Dec 2019 16:23:37 -0600 Subject: temporarily disable image cache --- bog.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bog.js b/bog.js index c5cb679..e9477ed 100644 --- a/bog.js +++ b/bog.js @@ -104,9 +104,9 @@ function getImage (id, keys, classList) { } localforage.getItem('image:' + id).then(cache => { - if (cache) { - return image.src = cache - } else { + //if (cache) { + // return image.src = cache + //} else { bog().then(log => { if (log) { for (var i = 0; i < log.length; i++) { @@ -124,7 +124,7 @@ function getImage (id, keys, classList) { } } }) - } + //} }) return image } -- cgit v1.2.3-70-g09d2 From 9983e7b768f2fc04376e3dfad7335a8a7941dbaa Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Tue, 31 Dec 2019 15:58:18 -0600 Subject: refactor gossip v 1.8.0 --- beacons.js | 24 ++++ bog.js | 2 +- gossip.js | 352 ++++++++++++++++++++++++++---------------------------- package-lock.json | 2 +- package.json | 2 +- render.js | 15 ++- server.js | 5 +- settings.js | 6 +- views.js | 8 +- 9 files changed, 216 insertions(+), 200 deletions(-) diff --git a/beacons.js b/beacons.js index 79f88a5..3c65f3e 100644 --- a/beacons.js +++ b/beacons.js @@ -84,5 +84,29 @@ function beaconsPage (keys) { ])) scroller.appendChild(ads) + + localforage.getItem('beacons').then(beacons => { + beacons.forEach(beacon => { + var message = h('div', {classList: 'message'}) + + if (beacon.signature) { + open(beacon).then(opened => { + quickName(beacon.author).then(gotName => { + message.appendChild(h('p', {innerHTML: marked(opened)})) + message.appendChild(h('span', [ + '—', + h('a', {href: '#' + beacon.author}, [gotName]), + ' from ', + h('a', {href: beacon.name}, [beacon.name]) + ]) + ) + }) + }) + } + + scroller.appendChild(message) + console.log(beacon) + }) + }) } diff --git a/bog.js b/bog.js index e9477ed..55188e5 100644 --- a/bog.js +++ b/bog.js @@ -76,7 +76,7 @@ async function unbox (boxed, sender, keys) { var nonceMsg = nacl.util.decodeBase64(boxed) var nonce = nonceMsg.slice(0, nacl.box.nonceLength) var msg = nonceMsg.slice(nacl.box.nonceLength, nonceMsg.length) - var message = nacl.box.open(msg, nonce, ed2curve.convertPublicKey(nacl.util.decodeBase64(sender.substring(1))), ed2curve.convertSecretKey(nacl.util.decodeBase64(keys.privateKey))) + var message = nacl.util.encodeUTF8(nacl.box.open(msg, nonce, ed2curve.convertPublicKey(nacl.util.decodeBase64(sender.substring(1))), ed2curve.convertSecretKey(nacl.util.decodeBase64(keys.privateKey)))) return message } diff --git a/gossip.js b/gossip.js index 0c12a40..47d40c1 100644 --- a/gossip.js +++ b/gossip.js @@ -1,198 +1,180 @@ -function sync (subs, keys) { +function processreq (req, pubkey, connection, keys) { + console.log(req) + if (req.box || req.signature) { + renderAd(req, keys) + } - var wsServers - - localforage.getItem('securepubs').then(function (servers) { - if (servers) { - wsServers = servers - } else { - servers = ['ws://bogbook.com', 'ws://localhost:8080'] - var pubs = [] - servers.forEach(server => { - var ws = new WebSocket(server) - ws.onopen = function () { - ws.send(JSON.stringify({requester: keys.publicKey, sendpub: true})) - } - ws.onmessage = function (message) { - pubs.push(server + '/~' + message.data) - localforage.setItem('securepubs', pubs) - } - }) - wsServers = pubs - } - }).then(function () { - subs.forEach(function (sub, index) { - setTimeout(function () { - wsServers.forEach(function (server, index) { - setTimeout(function () { - //console.log('SYNCING WITH: ' + server + ' to fetch ' + sub) - var split = server.split('~') - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) + if (req.seq === 0 || req.seq) { + console.log('feed sync') + bog(req.author).then(feed => { + if (feed) { + open(feed[0]).then(msg => { + if (req.seq > msg.seq) { + var reqdiff = JSON.stringify({author: req.author, seq: msg.seq}) + box(reqdiff, pubkey, keys).then(boxed => { + connection.send(JSON.stringify({ + requester: keys.publicKey, + box: boxed + })) + }) + } - bog(sub).then(srclog => { - if (srclog) { - open(srclog[0]).then(msg => { - ws.onopen = function () { - var message = JSON.stringify(msg) - // if we have a log then send the latest log and see if we get anything back - box(message, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - ws.onmessage = function (message) { - var req = JSON.parse(message.data) - unbox(req.box, req.requester, keys).then(unboxed => { - var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - if (unboxedreq.content) { - unboxedreq.signature = unboxedreq.content - renderAd(unboxedreq, keys) - } - if (unboxedreq.box) { - renderAd(unboxedreq, keys) - } - if (unboxedreq.seq === 0) { - var stringedfeed = JSON.stringify(srclog) - box(stringedfeed, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - //console.log('Sending entire log of ' + msg.author + ' to ' + serverpub) - ws.send(JSON.stringify(obj)) - }) - } - - if (unboxedreq.seq > msg.seq) { - //console.log('server feed is longer, requesting diff from server') - var reqdiff = JSON.stringify({author: unboxedreq.author, seq: msg.seq}) - box(reqdiff, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } + if (req.seq < msg.seq) { + var endrange = feed.length - req.seq - 25 + if (endrange < 0) { + endrange = feed.length - req.seq - 1 + } + var baserange = feed.length - req.seq + var diff = JSON.stringify( + feed.slice( + endrange, + baserange) + ) + box(diff, pubkey, keys).then(boxed => { + connection.send(JSON.stringify({ + requester: keys.publicKey, + box: boxed + })) + }) + } + }) + } else { console.log('we dont have it')} + }) + } - if (unboxedreq.seq < msg.seq) { - //console.log('server feed is shorter, sending diff to server') - var diff = JSON.stringify(srclog.slice(0, msg.seq - unboxedreq.seq)) - box(diff, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } + if (Array.isArray(req)) { + open(req[0]).then(msg => { + localforage.getItem(msg.author).then(feed => { + if (!feed) { + localforage.setItem(msg.author, req) + localforage.getItem('log').then(log => { + if (!log) { + var log = [] + } + for (var i = req.length -1; i >= 0; --i) { + open(req[i]).then(opened => { + log.unshift(opened) + var src = window.location.hash.substring(1) + if ((src === msg.author) || (src === '')) { + var scroller = document.getElementById('scroller') + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + } + if (opened.seq === req.length) { + log.sort((a, b) => a.timestamp - b.timestamp) + var reversed = log.reverse() + localforage.setItem('log', reversed) + } + }) + } + }) + } if (feed) { + open(feed[0]).then(lastmsg => { + if (req.length + lastmsg.seq === msg.seq) { + var newlog = req.concat(feed) + localforage.setItem(msg.author, newlog) + localforage.getItem('log').then(log => { + if (!log) { + var log = [] + } + for (var i = req.length -1; i >= 0; --i) { + open(req[i]).then(opened => { + log.unshift(opened) + var scroller = document.getElementById('scroller') - if (Array.isArray(unboxedreq)) { - //console.log('received diff from server') - open(unboxedreq[0]).then(msg => { - localforage.getItem(msg.author).then(feed => { - open(feed[0]).then(lastmsg => { - if (unboxedreq.length + lastmsg.seq === msg.seq) { - var newlog = unboxedreq.concat(feed) - localforage.setItem(msg.author, newlog).then(success => { - //console.log('combined existing feed of ' + msg.author + ' with diff and saved to client') - }) - localforage.getItem('log').then(log => { - if (!log) { - var log = [] - } - for (var i = unboxedreq.length -1; i >= 0; --i) { - open(unboxedreq[i]).then(opened => { - log.unshift(opened) - var scroller = document.getElementById('scroller') - - var src = window.location.hash.substring(1) - if ((src === sub) || (src === '')) { - var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) - } - if (unboxedreq.length + lastmsg.seq === opened.seq) { - log.sort((a, b) => a.timestamp - b.timestamp) - var reversed = log.reverse() - localforage.setItem('log', reversed).then(success => { - //console.log('saved log with ' + opened.author + ' prepended to localForage') - }) - } - }) - } - }) - } - }) - }) - }) - - } - - }) - } - }) - } else { - //console.log('NO LOG IN CLIENT') - ws.onopen = function () { - var reqwhole = JSON.stringify({author: sub, seq: 0}) - box(reqwhole, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed + var src = window.location.hash.substring(1) + if ((src === msg.author) || (src === '')) { + var scroller = document.getElementById('scroller') + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) } - ws.send(JSON.stringify(obj)) - }) - } - ws.onmessage = function (message) { - var req = JSON.parse(message.data) - //console.log('received message from ' + req.requester) - unbox(req.box, req.requester, keys).then(unboxed => { - var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - if (Array.isArray(unboxedreq)) { - open(unboxedreq[0]).then(msg => { - localforage.getItem(msg.author).then(feed => { - if (!feed) { - localforage.setItem(msg.author, unboxedreq).then(success => { - //console.log('saved log of ' + msg.author + ' to localforage') - }) - localforage.getItem('log').then(log => { - if (!log) { - var log = [] - } - for (var i = unboxedreq.length -1; i >= 0; --i) { - open(unboxedreq[i]).then(opened => { - log.unshift(opened) - var src = window.location.hash.substring(1) - if ((src === sub) || (src === '')) { - var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) - } - if (opened.seq === unboxedreq.length) { - log.sort((a, b) => a.timestamp - b.timestamp) - var reversed = log.reverse() - localforage.setItem('log', reversed).then(success => { - //console.log('saved log with ' + opened.author + ' prepended to localForage') - }) - } - }) - } - }) - } - }) - }) + if (req.length + lastmsg.seq === opened.seq) { + log.sort((a, b) => a.timestamp - b.timestamp) + var reversed = log.reverse() + localforage.setItem('log', reversed) } }) } - } + }) + } + }) + } + }) + }) + } +} + +function getpubkey (connection, keys) { + console.log('asking for pubkey') + connection.onopen = () => { + connection.send(JSON.stringify({ + requester: keys.publicKey, sendpub: true + })) + } + + connection.onmessage = (m) => { + console.log(m) + localforage.setItem(m.origin, m.data) + } +} + +function getfeed (feed, pubkey, connection, keys) { + bog(feed).then(log => { + var logseq = 0 + connection.onopen = () => { + if (log) { + open(log[0]).then(msg => { + box(JSON.stringify(msg), pubkey, keys).then(boxed => { + connection.send(JSON.stringify({ + requester: keys.publicKey, + box: boxed + })) + }) + logseq = msg.seq + }) + } else { + var msg = { + author: feed, + seq: logseq + } + box(JSON.stringify(msg), pubkey, keys).then(boxed => { + connection.send(JSON.stringify({ + requester: keys.publicKey, + box: boxed + })) + }) + } + } + connection.onmessage = (m) => { + var req = JSON.parse(m.data) + unbox(req.box, req.requester, keys).then(unboxed => { + var unboxedreq = JSON.parse(unboxed) + processreq(unboxedreq, pubkey, connection, keys) + }) + } + }) +} + +function sync (feeds, keys) { + var pubs + localforage.getItem('pubs').then(pubs => { + if (!pubs) { + pubs = ['ws://' + location.hostname + ':8080'] + localforage.setItem('pubs', pubs) + } + pubs.forEach(function (pub, index) { + setTimeout(function () { + console.log(pub) + var connection = new WebSocket(pub) + localforage.getItem(pub).then(pubkey => { + if (!pubkey) { + getpubkey(connection, keys) + } + if (pubkey) { + feeds.forEach(feed => { + getfeed(feed, pubkey, connection, keys) }) - }, index * 50000) + } }) - }, index * 20000) + }, index * 5000) }) }) } diff --git a/package-lock.json b/package-lock.json index 655685a..ad97945 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "bogbook", - "version": "1.7.0", + "version": "1.8.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ac7e569..a174152 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bogbook", - "version": "1.7.0", + "version": "1.8.0", "description": "secure blockchain logging (blogging, without the l) -- bogging", "main": "server.js", "scripts": { diff --git a/render.js b/render.js index 97798e6..f1e5511 100644 --- a/render.js +++ b/render.js @@ -21,7 +21,7 @@ function renderAd (ad, keys) { if (ad.box) { unbox(ad.box, ad.author, keys).then(unboxed => { if (unboxed) { - var msg = JSON.parse(nacl.util.encodeUTF8(unboxed)) + var msg = JSON.parse(unboxed) if (pmspot) { pmspot.parentNode.removeChild(pmspot) } @@ -65,6 +65,12 @@ function renderAd (ad, keys) { ws.send(JSON.stringify(obj)) localforage.setItem(ad.hash, true).then(success => { //console.log('heard: ' + ad.hash) + localforage.getItem('beacons').then(beacons => { + if (!beacons) { beacons = [] } + beacons.unshift(ad) + localforage.setItem('beacons', beacons) + }) + }) }) } @@ -100,8 +106,6 @@ function renderAd (ad, keys) { var serverpub = split[1] var ws = new WebSocket(serverurl) - - var tobox = { author: keys.publicKey, timestamp: Date.now(), @@ -122,6 +126,11 @@ function renderAd (ad, keys) { } ws.send(JSON.stringify(obj)) localforage.setItem(ad.hash, true).then(success => {console.log('heard: ' + ad.hash)}) + localforage.getItem('beacons').then(beacons => { + if (!beacons) { beacons = [] } + beacons.unshift(ad) + localforage.setItem('beacons', beacons) + }) }) } }) diff --git a/server.js b/server.js index e47f165..3904593 100644 --- a/server.js +++ b/server.js @@ -114,11 +114,12 @@ bog.keys().then(key => { wserve.on('connection', function (ws) { ws.on('message', function (message) { var req = JSON.parse(message) + console.log(req) if (req.sendpub) { ws.send(key.publicKey) } else { bog.unbox(req.box, req.requester, key).then(unboxed => { - var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) + var unboxedreq = JSON.parse(unboxed) //console.log(unboxedreq) if (unboxedreq.type == 'beacon') { if (unboxedreq.box) { @@ -169,7 +170,7 @@ bog.keys().then(key => { hash: obj.hash, name: config.fullurl, pub: 'ws://' + config.url + ':' + config.wsport + '/~' + key.publicKey, - content: obj.signature, + signature: obj.signature, views: obj.views } } diff --git a/settings.js b/settings.js index c88ea07..f5b341c 100644 --- a/settings.js +++ b/settings.js @@ -52,18 +52,18 @@ function settingsPage (keys) { var pubs = h('div', {classList: 'message'}) - pubs.appendChild(h('p', {innerHTML: marked('These are your bogbook pubs. Bogbook will gossip with these pubs to publish your messages and check for new messages from your subscriptions. You should have at least one Bogbook pub in order to gossip your messages. If you don\'t see a bogbook pub below, try clicking "Reset Pubs" or add \n```\nws://bogbook.com/~@h4e3bHDJeDWiCAkzp83HINPR4y7BLR7tI3fOVqwLQqw=\n```\n to your pubs list.')})) + pubs.appendChild(h('p', {innerHTML: marked('These are your bogbook pubs. Bogbook will gossip with these pubs to publish your messages and check for new messages from your subscriptions. You should have at least one Bogbook pub in order to gossip your messages. If you don\'t see a bogbook pub below, try clicking "Reset Pubs" or add \n```\nws://bogbook.com\n```\n to your pubs list.')})) var add = h('input', {placeholder: 'Add a pub'}) - localforage.getItem('securepubs').then(function (servers) { + localforage.getItem('pubs').then(function (servers) { pubs.appendChild(h('div', [ add, h('button', { onclick: function () { if (add.value) { servers.push(add.value) - localforage.setItem('securepubs', servers).then(function () { location.reload() }) + localforage.setItem('pubs', servers).then(function () { location.reload() }) } } }, ['Add a pub']) diff --git a/views.js b/views.js index b13d797..20cbd4b 100644 --- a/views.js +++ b/views.js @@ -15,10 +15,10 @@ function profilePage (src, keys) { var subs = [src] - var interval = 500 + var interval = 50 timer = function() { if (src === window.location.hash.substring(1)) { - if (interval < 10000) { interval = interval + 100 } + if (interval < 10000) { interval = interval + 50 } sync(subs, keys) setTimeout(timer, interval) } @@ -121,6 +121,7 @@ function searchPage (src, keys) { } function publicPage (keys) { + localforage.getItem('subscriptions').then(function (subs) { var interval = 1000 timer = function() { @@ -133,9 +134,8 @@ function publicPage (keys) { if (subs) { timer() } else { - var subs = [] + var subs = [keys.publickey] localforage.setItem('subscriptions', subs) - subs.push(keys.publicKey) timer() } }) -- cgit v1.2.3-70-g09d2 From cbf898a4ebda7f0edc3013f13bac61397bb51f7a Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Tue, 31 Dec 2019 17:31:54 -0600 Subject: fix pubs bug, and reqs to server on profile page were way too fast --- settings.js | 2 +- views.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/settings.js b/settings.js index f5b341c..b0cb561 100644 --- a/settings.js +++ b/settings.js @@ -75,7 +75,7 @@ function settingsPage (keys) { h('button', { onclick: function () { var newServers = servers.filter(item => item !== pub) - localforage.setItem('securepubs', newServers).then(function () { location.reload() }) + localforage.setItem('pubs', newServers).then(function () { location.reload() }) } }, ['Remove']) ])) diff --git a/views.js b/views.js index 20cbd4b..6d1fb59 100644 --- a/views.js +++ b/views.js @@ -15,7 +15,7 @@ function profilePage (src, keys) { var subs = [src] - var interval = 50 + var interval = 500 timer = function() { if (src === window.location.hash.substring(1)) { if (interval < 10000) { interval = interval + 50 } -- cgit v1.2.3-70-g09d2 From 2d741344de4f2ad3d6c1271f68ff1e313b59ef69 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Wed, 1 Jan 2020 10:10:55 -0600 Subject: send random number of posts between 1 and 50, adjust client request speed --- server.js | 3 +-- views.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index 3904593..4e4a471 100644 --- a/server.js +++ b/server.js @@ -114,7 +114,6 @@ bog.keys().then(key => { wserve.on('connection', function (ws) { ws.on('message', function (message) { var req = JSON.parse(message) - console.log(req) if (req.sendpub) { ws.send(key.publicKey) } else { @@ -221,7 +220,7 @@ bog.keys().then(key => { }) } if (unboxedreq.seq < msg.seq) { - var endrange = feed.length - unboxedreq.seq - 25 + var endrange = feed.length - unboxedreq.seq - Math.floor(Math.random() * 50 + 1) if (endrange < 0) { endrange = feed.length - unboxedreq.seq - 1 } diff --git a/views.js b/views.js index 6d1fb59..e967191 100644 --- a/views.js +++ b/views.js @@ -15,7 +15,7 @@ function profilePage (src, keys) { var subs = [src] - var interval = 500 + var interval = 2500 timer = function() { if (src === window.location.hash.substring(1)) { if (interval < 10000) { interval = interval + 50 } -- cgit v1.2.3-70-g09d2 From e8d59952197d2dc7cfeede08de15e535f466621a Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Wed, 1 Jan 2020 19:27:54 -0600 Subject: got to create the bogbook folder before the config --- server.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index 4e4a471..deb1f07 100644 --- a/server.js +++ b/server.js @@ -6,6 +6,9 @@ var bogdir = path + 'bogs/' var addir = path + 'ads/' var confpath = path + 'config.json' +if (!fs.existsSync(homedir + '/.bogbook/')) {fs.mkdirSync(homedir + '/.bogbook/')} +if (!fs.existsSync(bogdir)){fs.mkdirSync(bogdir)} + if (fs.existsSync(confpath)) { console.log('loading config from ' + confpath) var config = require(confpath) @@ -23,9 +26,6 @@ if (fs.existsSync(confpath)) { console.log(config) -if (!fs.existsSync(homedir + '/.bogbook/')) {fs.mkdirSync(homedir + '/.bogbook/')} -if (!fs.existsSync(bogdir)){fs.mkdirSync(bogdir)} - if (process.argv[2] === 'verbose') { var VERBOSE = true } else { -- cgit v1.2.3-70-g09d2 From 8da504b074b76d0a811f388181d55b0ed3ce3294 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Wed, 1 Jan 2020 19:34:37 -0600 Subject: try to fix adfiles error --- server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.js b/server.js index deb1f07..ad802d1 100644 --- a/server.js +++ b/server.js @@ -158,7 +158,7 @@ bog.keys().then(key => { if (config.ads) { if (Math.floor(Math.random() * 6) == 2) { fs.readdir(addir, function (err, adfiles) { - if (adfiles[0]) { + if (adfiles) { var num = Math.floor(Math.random() * (adfiles.length)) fs.readFile(addir + adfiles[num], 'UTF-8', function (err, adFile) { var obj = JSON.parse(adFile) -- cgit v1.2.3-70-g09d2 From 508e4c53a93cfa443dd590dd52f8fc22471d9e7c Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 3 Jan 2020 15:57:10 -0600 Subject: rip out beacons --- app.js | 3 -- beacons.js | 112 --------------------------------------- gossip.js | 10 +--- index.html | 1 - package-lock.json | 2 +- package.json | 2 +- render.js | 153 ------------------------------------------------------ server.js | 80 ---------------------------- 8 files changed, 4 insertions(+), 359 deletions(-) delete mode 100644 beacons.js diff --git a/app.js b/app.js index 5dd49a5..7fe1ae2 100644 --- a/app.js +++ b/app.js @@ -10,8 +10,6 @@ function route (keys) { if (src === 'settings') { settingsPage(keys) - } else if (src === 'beacons') { - beaconsPage(keys) } else if (src[0] === '@') { profilePage(src, keys) } else if (src[0] === '?') { @@ -30,7 +28,6 @@ keys().then(key => { h('div', {classList: 'internal'}, [ h('li', [h('a', {href: '#'}, ['Home'])]), h('li', [h('a', {href: '#' + key.publicKey}, [getName(key.publicKey, keys)])]), - h('li', [h('a', {href: '#beacons'}, ['Beacons'])]), h('li', {classList: 'right'}, [h('a', {href: '#settings'}, ['Settings'])]), h('form', { classList: 'search', onsubmit: function (e) { diff --git a/beacons.js b/beacons.js deleted file mode 100644 index 3c65f3e..0000000 --- a/beacons.js +++ /dev/null @@ -1,112 +0,0 @@ -function beaconsPage (keys) { - - var pubslist = h('select') - - localforage.getItem('securepubs').then(function (servers) { - servers.forEach(function (pub) { - pubslist.appendChild( - h('option', {value: pub}, [pub]) - ) - }) - }) - - var ads = h('div', {classList: 'message'}) - - ads.appendChild(h('span', {innerHTML: marked('Sometimes when you\'re lost on the Internet you might want to send out a beacon so that people can see you. \n\n Beacons from guests will run for 100 views before they are deleted by the pub. \n\nSelect a pub:')})) - - ads.appendChild(pubslist) - - var recp = h('input', {placeholder: 'Ex: @Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0='}) - - var adstext = h('textarea', {placeholder: 'Hello World!'}) - - ads.appendChild(h('span', [ - h('br'), - h('p', [" Send a beacon (leave the 'To:' field blank for a public beacon): "]), - h('p', ['To: ', - recp - ]), - adstext, - h('br'), - h('button', { - onclick: function () { - var split = pubslist.value.split('~') - console.log(split) - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) - - if ((recp.value) && (adstext.value)) { - var tobox = { - author: keys.publicKey, - timestamp: Date.now(), - content: adstext.value - } - box(JSON.stringify(tobox), recp.value, keys).then(boxedmsg => { - var msg = { - type: 'beacon', - author: keys.publicKey, - box: boxedmsg - } - ws.onopen = function () { - box(JSON.stringify(msg), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - adstext.value = '' - recp.value = '' - } - }) - } - - if ((!recp.value) && (adstext.value)) { - var msg = { - type: 'beacon', - author: keys.publicKey - } - msg.signature = nacl.util.encodeBase64(nacl.sign(nacl.util.decodeUTF8(JSON.stringify(adstext.value)), nacl.util.decodeBase64(keys.privateKey))) - ws.onopen = function () { - box(JSON.stringify(msg), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - adstext.value = '' - } - } - } - }, ['Publish']) - ])) - - scroller.appendChild(ads) - - localforage.getItem('beacons').then(beacons => { - beacons.forEach(beacon => { - var message = h('div', {classList: 'message'}) - - if (beacon.signature) { - open(beacon).then(opened => { - quickName(beacon.author).then(gotName => { - message.appendChild(h('p', {innerHTML: marked(opened)})) - message.appendChild(h('span', [ - '—', - h('a', {href: '#' + beacon.author}, [gotName]), - ' from ', - h('a', {href: beacon.name}, [beacon.name]) - ]) - ) - }) - }) - } - - scroller.appendChild(message) - console.log(beacon) - }) - }) -} - diff --git a/gossip.js b/gossip.js index 47d40c1..809266e 100644 --- a/gossip.js +++ b/gossip.js @@ -1,11 +1,5 @@ function processreq (req, pubkey, connection, keys) { - console.log(req) - if (req.box || req.signature) { - renderAd(req, keys) - } - if (req.seq === 0 || req.seq) { - console.log('feed sync') bog(req.author).then(feed => { if (feed) { open(feed[0]).then(msg => { @@ -38,7 +32,7 @@ function processreq (req, pubkey, connection, keys) { }) } }) - } else { console.log('we dont have it')} + } }) } @@ -157,7 +151,7 @@ function sync (feeds, keys) { var pubs localforage.getItem('pubs').then(pubs => { if (!pubs) { - pubs = ['ws://' + location.hostname + ':8080'] + pubs = ['ws://' + location.hostname + ':8080', 'ws://bogbook.com'] localforage.setItem('pubs', pubs) } pubs.forEach(function (pub, index) { diff --git a/index.html b/index.html index 5d18890..0396bcc 100644 --- a/index.html +++ b/index.html @@ -17,7 +17,6 @@ - diff --git a/package-lock.json b/package-lock.json index ad97945..e17dee8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "bogbook", - "version": "1.8.0", + "version": "1.8.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a174152..437d4c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bogbook", - "version": "1.8.0", + "version": "1.8.1", "description": "secure blockchain logging (blogging, without the l) -- bogging", "main": "server.js", "scripts": { diff --git a/render.js b/render.js index f1e5511..e807c1e 100644 --- a/render.js +++ b/render.js @@ -1,156 +1,3 @@ -function renderAd (ad, keys) { - localforage.getItem(ad.hash).then(heard => { - if (!heard) { - var screen = document.getElementById('screen') - var adspot = document.getElementById('ad') - var pmspot = document.getElementById('pm') - - if (adspot) { - adspot.parentNode.removeChild(adspot) - } - - - var adspace = h('span') - - if (ad.views) { - adspace.appendChild(h('span', {classList: 'right'}, [h('pre', [ad.views + ' views'])])) - } else { - adspace.appendChild(h('span', {classList: 'right'}, [h('pre', ['beacon'])])) - } - - if (ad.box) { - unbox(ad.box, ad.author, keys).then(unboxed => { - if (unboxed) { - var msg = JSON.parse(unboxed) - if (pmspot) { - pmspot.parentNode.removeChild(pmspot) - } - quickName(ad.author).then(gotName => { - beacon = h('div', {id: 'pm'}, [ - h('span', {classList: 'right'}, [h('pre', [human(new Date(msg.timestamp))])]), - h('p', {innerHTML: marked(msg.content)}), - h('button', {classList: 'right', - onclick: function () { - pmspot = document.getElementById('pm') - pmspot.parentNode.removeChild(pmspot) - if (msg.content.substring((msg.content.length - 6), msg.content.length) === 'Heard.') { - localforage.setItem(ad.hash, true).then(success => { - //console.log('heard: ' + ad.hash) - }) - - } else { - var split = ad.pub.split('~') - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) - - var tobox = { - author: keys.publicKey, - timestamp: Date.now(), - content: '>' + msg.content + '\n\nHeard.' - } - - box(JSON.stringify(tobox), ad.author, keys).then(boxedmsg => { - var msg = { - type: 'beacon', - author: keys.publicKey, - box: boxedmsg - } - ws.onopen = function () { - box(JSON.stringify(msg), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - localforage.setItem(ad.hash, true).then(success => { - //console.log('heard: ' + ad.hash) - localforage.getItem('beacons').then(beacons => { - if (!beacons) { beacons = [] } - beacons.unshift(ad) - localforage.setItem('beacons', beacons) - }) - - }) - }) - } - }) - } - } - }, ['Heard']), - h('span', [ - '—', - h('a', {href: '#' + ad.author}, [gotName]), - ' from ', - h('a', {href: ad.name}, [ad.name]) - ]) - ]) - screen.append(beacon) - }) - } - }) - } - - if (ad.signature) { - open(ad).then(opened => { - quickName(ad.author).then(gotName => { - newAd = h('div', {id: 'ad'}, [ - adspace, - h('p', {innerHTML: marked(opened)}), - h('button', {classList: 'right', - onclick: function () { - adspot = document.getElementById('ad') - adspot.parentNode.removeChild(adspot) - var split = ad.pub.split('~') - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) - - var tobox = { - author: keys.publicKey, - timestamp: Date.now(), - content: '>' + opened + '\n\nHeard.' - } - - box(JSON.stringify(tobox), ad.author, keys).then(boxedmsg => { - var msg = { - type: 'beacon', - author: keys.publicKey, - box: boxedmsg - } - ws.onopen = function () { - box(JSON.stringify(msg), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - localforage.setItem(ad.hash, true).then(success => {console.log('heard: ' + ad.hash)}) - localforage.getItem('beacons').then(beacons => { - if (!beacons) { beacons = [] } - beacons.unshift(ad) - localforage.setItem('beacons', beacons) - }) - }) - } - }) - } - }, ['Heard']), - h('span', [ - '—', - h('a', {href: '#' + ad.author}, [gotName]), - ' from ', - h('a', {href: ad.name}, [ad.name]) - ]) - ]) - screen.appendChild(newAd) - }) - }) - } - } - }) -} - function getHeader (post, keys, mini) { var getRaw = h('button', { onclick: function () { diff --git a/server.js b/server.js index ad802d1..fbe92e0 100644 --- a/server.js +++ b/server.js @@ -3,7 +3,6 @@ var homedir = require('os').homedir() var path = homedir + '/.bogbook/' var bogdir = path + 'bogs/' -var addir = path + 'ads/' var confpath = path + 'config.json' if (!fs.existsSync(homedir + '/.bogbook/')) {fs.mkdirSync(homedir + '/.bogbook/')} @@ -120,33 +119,6 @@ bog.keys().then(key => { bog.unbox(req.box, req.requester, key).then(unboxed => { var unboxedreq = JSON.parse(unboxed) //console.log(unboxedreq) - if (unboxedreq.type == 'beacon') { - if (unboxedreq.box) { - var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.box))).toString('hex') - - var obj = { - hash: hex, - author: unboxedreq.author, - box: unboxedreq.box, - views: 0 - } - } - - if (unboxedreq.signature) { - var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.signature))).toString('hex') - var obj = { - hash: hex, - author: unboxedreq.author, - signature: unboxedreq.signature, - views: 0 - } - } - - fs.writeFile(addir + hex, JSON.stringify(obj), 'UTF-8', function () { - console.log('Saved as ' + hex) - }) - ws.close() - } if (unboxedreq.seq >= 0) { printAsk(req, unboxedreq) fs.readFile(bogdir + unboxedreq.author, 'UTF-8', function (err, data) { @@ -155,58 +127,6 @@ bog.keys().then(key => { bog.open(feed[0]).then(msg => { if (unboxedreq.seq === msg.seq) { printFeedIdentical(msg, req) - if (config.ads) { - if (Math.floor(Math.random() * 6) == 2) { - fs.readdir(addir, function (err, adfiles) { - if (adfiles) { - var num = Math.floor(Math.random() * (adfiles.length)) - fs.readFile(addir + adfiles[num], 'UTF-8', function (err, adFile) { - var obj = JSON.parse(adFile) - - if (obj.signature) { - var ad = { - author: obj.author, - hash: obj.hash, - name: config.fullurl, - pub: 'ws://' + config.url + ':' + config.wsport + '/~' + key.publicKey, - signature: obj.signature, - views: obj.views - } - } - - if (obj.box) { - var ad = { - author: obj.author, - hash: obj.hash, - name: config.fullurl, - pub: 'ws://' + config.url + ':' + config.wsport + '/~' + key.publicKey, - box: obj.box, - views: obj.views - } - } - - if ((obj.views > 100) && (obj.author != config.author)) { - fs.unlinkSync(addir + obj.hash) - //console.log('REMOVING AD') - } else { - obj.views++ - fs.writeFileSync(addir + obj.hash, JSON.stringify(obj), 'UTF-8') - } - printSendAd(ad, req) - //console.log('SENDING AD') - bog.box(JSON.stringify(ad), req.requester, key).then(boxed => { - sendobj = { - requester: key.publicKey, - box: boxed - } - ws.send(JSON.stringify(sendobj)) - ws.close() - }) - }) - } - }) - } - } } if (unboxedreq.seq > msg.seq) { printClientLonger(msg, req) -- cgit v1.2.3-70-g09d2 From 95812d4b1d5cb7c025c6b7940b9dbd9e723b855d Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 3 Jan 2020 15:58:45 -0600 Subject: change wording to "added an image to" --- render.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/render.js b/render.js index e807c1e..79f839a 100644 --- a/render.js +++ b/render.js @@ -178,9 +178,9 @@ function render (msg, keys, preview) { message.appendChild(getHeader(msg, keys, mini)) } else if (msg.type == 'image') { var mini = h('span', [ - ' identified ', + ' added an image to ', h('a', { href: '#' + msg.imaged }, [msg.imaged.substring(0, 10) + '...']), - ' as ', + ' ', h('img', {src: msg.image, classList: 'avatar'}) ]) message.appendChild(getHeader(msg, keys, mini)) -- cgit v1.2.3-70-g09d2 From 9f8817829f01391567989697394417474205dace Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 3 Jan 2020 17:21:37 -0600 Subject: remove more beacon stuff --- server.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/server.js b/server.js index fbe92e0..15135c0 100644 --- a/server.js +++ b/server.js @@ -16,7 +16,6 @@ if (fs.existsSync(confpath)) { port: '8089', wsport: '8080', url: 'localhost', - ads: true, author: '@Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0=' } config.fullurl = 'http://' + config.url + ':' + config.port + '/' @@ -32,7 +31,6 @@ if (process.argv[2] === 'verbose') { } console.log('Verbose output is ' + VERBOSE + ' run with `node server verbose` to see all output') -console.log('Advertisements are ' + config.ads) // log messages @@ -80,12 +78,6 @@ function printFeedIdentical (msg, req) { } } -function printSendAd (msg, req) { - if (VERBOSE) { - console.log('sent ad ' + msg.content + ' to ' + req.requester) - } -} - // static server (8089) var serve = require('koa-static-server') -- cgit v1.2.3-70-g09d2 From edf8b1193d82e7976c6c819aa1d25d54cc2c1858 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 3 Jan 2020 18:42:43 -0600 Subject: condense reply text into a ↳ symbol -- also render text of message that is being replied to MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bog.js | 12 ++++++++++++ css/style.css | 2 +- render.js | 22 +++++++++++++++++----- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/bog.js b/bog.js index 55188e5..d8ee2a8 100644 --- a/bog.js +++ b/bog.js @@ -94,6 +94,18 @@ async function get (key) { } } +async function getTitle (key) { + var log = await localforage.getItem('log') + if (log != null) { + for (var i = log.length - 1; i >= 0; --i) { + if (log[i].key === key) { + return log[i].text.substring(0, 15) + '…' + } + } + } +} + + // bog.getImage function getImage (id, keys, classList) { diff --git a/css/style.css b/css/style.css index 6e26838..ba2313a 100644 --- a/css/style.css +++ b/css/style.css @@ -9,7 +9,7 @@ body { } p { - margin-top: 1ex; + margin-top: .5ex; margin-bottom: 1ex; font-size: 1em; } diff --git a/render.js b/render.js index 79f839a..aaea0c2 100644 --- a/render.js +++ b/render.js @@ -138,14 +138,26 @@ function render (msg, keys, preview) { } if (msg.type == 'post') { - message.appendChild(getHeader(msg, keys)) + var mini = h('span', [' ']) + + message.appendChild(getHeader(msg, keys, mini)) + + console.log(getTitle(msg.reply)) if (msg.reply) { - message.firstChild.appendChild(h('span', [ - 're: ', - h('a', {href: '#' + msg.reply}, [msg.reply.substring(0, 10) + '...']) - ])) + getTitle(msg.reply).then(title => { + if (!title) { + title = msg.reply.substring(0, 15) + '…' + } + mini.appendChild(h('span', [ + '↳ ', + h('a', {href: '#' + msg.reply}, [title]) + ])) + + }) } + + message.appendChild(h('div',{id: 'content:' + msg.key, innerHTML: marked(msg.text)})) var buttons = h('div') if (!preview) { -- cgit v1.2.3-70-g09d2 From 8b1e4b587d2c8f7818d8d8745cdabada9e0d41d0 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 5 Jan 2020 17:35:17 -0600 Subject: add profile photos to navbar and limit number of mentions that arrive --- app.js | 10 ++++++++-- css/style.css | 4 ++-- views.js | 24 ++++++++++++++++++++---- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/app.js b/app.js index 7fe1ae2..7892593 100644 --- a/app.js +++ b/app.js @@ -26,8 +26,14 @@ keys().then(key => { var navbar = h('div', {classList: 'navbar'}, [ h('div', {classList: 'internal'}, [ - h('li', [h('a', {href: '#'}, ['Home'])]), - h('li', [h('a', {href: '#' + key.publicKey}, [getName(key.publicKey, keys)])]), + h('li', [h('a', {href: '#' + key.publicKey}, + [ + getImage(key.publicKey, keys), + getName(key.publicKey, keys) + ]) + ]), + h('li', [h('a', {href: '#'}, ['All'])]), + h('li', [h('a', {href: '#?' + key.publicKey}, ['Mentions'])]), h('li', {classList: 'right'}, [h('a', {href: '#settings'}, ['Settings'])]), h('form', { classList: 'search', onsubmit: function (e) { diff --git a/css/style.css b/css/style.css index ba2313a..383d6b9 100644 --- a/css/style.css +++ b/css/style.css @@ -180,7 +180,7 @@ textarea { z-index: 1000; margin: 0; padding-top: .33em; - padding-bottom: .27em; + padding-bottom: .4em; left: 0; right: 0; top: 0; } @@ -236,7 +236,7 @@ form.search { } .profileAvatar { width: 75px; vertical-align: top; border-radius: 5px; object-fit: cover; margin-right: .25em; margin-bottom: .25em;} -.avatar { width: 25px; height: 25px; vertical-align: middle; object-fit: cover; border-radius: 5px; margin-right: .2em; } +.avatar { width: 25px; height: 25px; vertical-align: middle; object-fit: cover; border-radius: 5px; margin-right: .5em; } .image { width: 75px; height: 75px; object-fit: cover; margin-right: .2em; border-radius: 5px; cursor: pointer;} diff --git a/views.js b/views.js index e967191..d8c537f 100644 --- a/views.js +++ b/views.js @@ -107,12 +107,28 @@ function profilePage (src, keys) { function searchPage (src, keys) { var search = src.substring(1).replace("%20"," ").toUpperCase() + + async function addPosts (posts, keys) { + posts.forEach(function (msg) { + if (msg.text) { + if (msg.text.toUpperCase().includes(search)) { + scroller.appendChild(render(msg, keys)) + } + } + }) + } bog().then(log => { + var index = 0 if (log) { - log.forEach(function (msg) { - if (msg.text) { - if (msg.text.toUpperCase().includes(search)) { - scroller.appendChild(render(msg, keys)) + var posts = log.slice(index, index + 25) + addPosts(posts, keys).then(done => { + index = index + 25 + window.onscroll = function(ev) { + if (((window.innerHeight + window.scrollY) >= document.body.scrollHeight) && (window.location.hash.substring(1) === src)) { + posts = log.slice(index, index + 25) + index = index + 25 + addPosts(posts, keys) + console.log("Bottom of page") } } }) -- cgit v1.2.3-70-g09d2 From cc9eca00f3670b56dc888ff15e7e2ed8354c9d8e Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 5 Jan 2020 17:44:59 -0600 Subject: put image and name in different divs --- app.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app.js b/app.js index 7892593..5aa7d1e 100644 --- a/app.js +++ b/app.js @@ -29,6 +29,10 @@ keys().then(key => { h('li', [h('a', {href: '#' + key.publicKey}, [ getImage(key.publicKey, keys), + ]) + ]), + h('li', [h('a', {href: '#' + key.publicKey}, + [ getName(key.publicKey, keys) ]) ]), -- cgit v1.2.3-70-g09d2 From 4614d28969667b6c79a9195ef459942dea3ea546 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 5 Jan 2020 17:47:31 -0600 Subject: adjust spacing --- css/style.css | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/css/style.css b/css/style.css index 383d6b9..7ec1ee4 100644 --- a/css/style.css +++ b/css/style.css @@ -38,7 +38,7 @@ hr { #screen { position: absolute; - top: 35px; + top: 40px; right: 0; left: 0; bottom: 0; @@ -179,8 +179,8 @@ textarea { position: fixed; z-index: 1000; margin: 0; - padding-top: .33em; - padding-bottom: .4em; + padding-top: .4em; + padding-bottom: .3em; left: 0; right: 0; top: 0; } -- cgit v1.2.3-70-g09d2 From df5dd87b165d3496e808b5ab443ed5f919f3e88c Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 10 Jan 2020 09:24:18 -0600 Subject: attempt to fix bug where subs end up as null --- gossip.js | 40 ++++++++++++++++++++++++---------------- render.js | 2 -- views.js | 18 ++++++++++++++++-- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/gossip.js b/gossip.js index 809266e..828b471 100644 --- a/gossip.js +++ b/gossip.js @@ -1,11 +1,15 @@ function processreq (req, pubkey, connection, keys) { + console.log('processreq') if (req.seq === 0 || req.seq) { bog(req.author).then(feed => { if (feed) { + console.log('opening first message') open(feed[0]).then(msg => { + console.log(msg) if (req.seq > msg.seq) { var reqdiff = JSON.stringify({author: req.author, seq: msg.seq}) box(reqdiff, pubkey, keys).then(boxed => { + console.log(boxed) connection.send(JSON.stringify({ requester: keys.publicKey, box: boxed @@ -25,6 +29,7 @@ function processreq (req, pubkey, connection, keys) { baserange) ) box(diff, pubkey, keys).then(boxed => { + console.log(boxed) connection.send(JSON.stringify({ requester: keys.publicKey, box: boxed @@ -42,9 +47,7 @@ function processreq (req, pubkey, connection, keys) { if (!feed) { localforage.setItem(msg.author, req) localforage.getItem('log').then(log => { - if (!log) { - var log = [] - } + if (!log) { var log = [] } for (var i = req.length -1; i >= 0; --i) { open(req[i]).then(opened => { log.unshift(opened) @@ -54,36 +57,30 @@ function processreq (req, pubkey, connection, keys) { scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) } if (opened.seq === req.length) { - log.sort((a, b) => a.timestamp - b.timestamp) - var reversed = log.reverse() - localforage.setItem('log', reversed) + localforage.setItem('log', log) } }) } }) - } if (feed) { + } + if (feed) { open(feed[0]).then(lastmsg => { + console.log(lastmsg) if (req.length + lastmsg.seq === msg.seq) { var newlog = req.concat(feed) localforage.setItem(msg.author, newlog) localforage.getItem('log').then(log => { - if (!log) { - var log = [] - } + if (!log) { var log = [] } for (var i = req.length -1; i >= 0; --i) { open(req[i]).then(opened => { log.unshift(opened) - var scroller = document.getElementById('scroller') - var src = window.location.hash.substring(1) if ((src === msg.author) || (src === '')) { var scroller = document.getElementById('scroller') scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) } if (req.length + lastmsg.seq === opened.seq) { - log.sort((a, b) => a.timestamp - b.timestamp) - var reversed = log.reverse() - localforage.setItem('log', reversed) + localforage.setItem('log', log) } }) } @@ -111,12 +108,18 @@ function getpubkey (connection, keys) { } function getfeed (feed, pubkey, connection, keys) { + console.log('getfeed') bog(feed).then(log => { var logseq = 0 connection.onopen = () => { if (log) { + console.log('onopen') + console.log(log[0]) + // for some reason this does not open below open(log[0]).then(msg => { - box(JSON.stringify(msg), pubkey, keys).then(boxed => { + var string = JSON.stringify(msg) + box(string, pubkey, keys).then(boxed => { + console.log(boxed) connection.send(JSON.stringify({ requester: keys.publicKey, box: boxed @@ -125,6 +128,7 @@ function getfeed (feed, pubkey, connection, keys) { logseq = msg.seq }) } else { + console.log('else') var msg = { author: feed, seq: logseq @@ -138,6 +142,7 @@ function getfeed (feed, pubkey, connection, keys) { } } connection.onmessage = (m) => { + console.log('onmessage') var req = JSON.parse(m.data) unbox(req.box, req.requester, keys).then(unboxed => { var unboxedreq = JSON.parse(unboxed) @@ -163,7 +168,10 @@ function sync (feeds, keys) { getpubkey(connection, keys) } if (pubkey) { + console.log(pubkey) + console.log(feeds) feeds.forEach(feed => { + console.log('getting ' + feed) getfeed(feed, pubkey, connection, keys) }) } diff --git a/render.js b/render.js index aaea0c2..e440abd 100644 --- a/render.js +++ b/render.js @@ -142,8 +142,6 @@ function render (msg, keys, preview) { message.appendChild(getHeader(msg, keys, mini)) - console.log(getTitle(msg.reply)) - if (msg.reply) { getTitle(msg.reply).then(title => { if (!title) { diff --git a/views.js b/views.js index d8c537f..b964915 100644 --- a/views.js +++ b/views.js @@ -138,7 +138,13 @@ function searchPage (src, keys) { function publicPage (keys) { - localforage.getItem('subscriptions').then(function (subs) { + localforage.getItem('log').then(log => { + log.sort((a, b) => a.timestamp - b.timestamp) + var reversed = log.reverse() + localforage.setItem('log', reversed) + }) + + localforage.getItem('subscriptions').then(subs => { var interval = 1000 timer = function() { if ('' === window.location.hash.substring(1)) { @@ -148,9 +154,17 @@ function publicPage (keys) { } } if (subs) { + // the next two lines just fix a bug where the first sub was being set to null. Delete this code after March 2020. + subs.forEach(sub => { + if (sub == null) { + var subs = [keys.publicKey] + localforage.setItem('subscriptions', subs) + } + }) timer() } else { - var subs = [keys.publickey] + var subs = [keys.publicKey] + console.log(subs) localforage.setItem('subscriptions', subs) timer() } -- cgit v1.2.3-70-g09d2 From 5f47d7c1ca5e5baed3180c125844803804a8a7a1 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 10 Jan 2020 13:52:42 -0600 Subject: remove console.logs --- gossip.js | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/gossip.js b/gossip.js index 828b471..26915b1 100644 --- a/gossip.js +++ b/gossip.js @@ -1,15 +1,11 @@ function processreq (req, pubkey, connection, keys) { - console.log('processreq') if (req.seq === 0 || req.seq) { bog(req.author).then(feed => { if (feed) { - console.log('opening first message') open(feed[0]).then(msg => { - console.log(msg) if (req.seq > msg.seq) { var reqdiff = JSON.stringify({author: req.author, seq: msg.seq}) box(reqdiff, pubkey, keys).then(boxed => { - console.log(boxed) connection.send(JSON.stringify({ requester: keys.publicKey, box: boxed @@ -29,7 +25,6 @@ function processreq (req, pubkey, connection, keys) { baserange) ) box(diff, pubkey, keys).then(boxed => { - console.log(boxed) connection.send(JSON.stringify({ requester: keys.publicKey, box: boxed @@ -65,7 +60,6 @@ function processreq (req, pubkey, connection, keys) { } if (feed) { open(feed[0]).then(lastmsg => { - console.log(lastmsg) if (req.length + lastmsg.seq === msg.seq) { var newlog = req.concat(feed) localforage.setItem(msg.author, newlog) @@ -94,7 +88,6 @@ function processreq (req, pubkey, connection, keys) { } function getpubkey (connection, keys) { - console.log('asking for pubkey') connection.onopen = () => { connection.send(JSON.stringify({ requester: keys.publicKey, sendpub: true @@ -102,24 +95,18 @@ function getpubkey (connection, keys) { } connection.onmessage = (m) => { - console.log(m) localforage.setItem(m.origin, m.data) } } function getfeed (feed, pubkey, connection, keys) { - console.log('getfeed') bog(feed).then(log => { var logseq = 0 connection.onopen = () => { if (log) { - console.log('onopen') - console.log(log[0]) - // for some reason this does not open below open(log[0]).then(msg => { var string = JSON.stringify(msg) box(string, pubkey, keys).then(boxed => { - console.log(boxed) connection.send(JSON.stringify({ requester: keys.publicKey, box: boxed @@ -128,7 +115,6 @@ function getfeed (feed, pubkey, connection, keys) { logseq = msg.seq }) } else { - console.log('else') var msg = { author: feed, seq: logseq @@ -142,7 +128,6 @@ function getfeed (feed, pubkey, connection, keys) { } } connection.onmessage = (m) => { - console.log('onmessage') var req = JSON.parse(m.data) unbox(req.box, req.requester, keys).then(unboxed => { var unboxedreq = JSON.parse(unboxed) @@ -161,17 +146,13 @@ function sync (feeds, keys) { } pubs.forEach(function (pub, index) { setTimeout(function () { - console.log(pub) var connection = new WebSocket(pub) localforage.getItem(pub).then(pubkey => { if (!pubkey) { getpubkey(connection, keys) } if (pubkey) { - console.log(pubkey) - console.log(feeds) feeds.forEach(feed => { - console.log('getting ' + feed) getfeed(feed, pubkey, connection, keys) }) } -- cgit v1.2.3-70-g09d2 From cb59e302155933359a8500b3094b1fb495c89afb Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 10 Jan 2020 17:47:28 -0600 Subject: add background photos -- not quite done yet --- css/style.css | 7 +++++- gossip.js | 4 +-- identify.js | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- render.js | 16 ++++++++++-- views.js | 24 ++++++++++++++++-- 5 files changed, 119 insertions(+), 10 deletions(-) diff --git a/css/style.css b/css/style.css index 7ec1ee4..df53ffe 100644 --- a/css/style.css +++ b/css/style.css @@ -59,11 +59,16 @@ hr { .message, .profile { border: 1px solid #ddd; background: white; - margin-top: .5em; + margin-bottom: .5em; padding: .3em .5em; +} + +.message { border-radius: 5px; } +.banner { height: 275px; } + #scroller:last-child { margin-bottom: 10em; } .message, .message > *, .navbar, .navbar > *, #ad, #ad > *, #viewer > * { diff --git a/gossip.js b/gossip.js index 26915b1..5cf19e9 100644 --- a/gossip.js +++ b/gossip.js @@ -49,7 +49,7 @@ function processreq (req, pubkey, connection, keys) { var src = window.location.hash.substring(1) if ((src === msg.author) || (src === '')) { var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + scroller.insertBefore(render(opened, keys), scroller.childNodes[2]) } if (opened.seq === req.length) { localforage.setItem('log', log) @@ -71,7 +71,7 @@ function processreq (req, pubkey, connection, keys) { var src = window.location.hash.substring(1) if ((src === msg.author) || (src === '')) { var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + scroller.insertBefore(render(opened, keys), scroller.childNodes[2]) } if (req.length + lastmsg.seq === opened.seq) { localforage.setItem('log', log) diff --git a/identify.js b/identify.js index 1381c6f..eb8827c 100644 --- a/identify.js +++ b/identify.js @@ -8,6 +8,72 @@ function identify (src, profile, keys) { var photoURL = {} + // this could be a hell of a lot dry-er + + // also we need to get rid of UI glitches when you hit the cancel button (it should return to the same state it started in) + + var newBackground = h('span', [ + h('input', {id: 'input', type: 'file', + onclick: function () { + var canvas = document.getElementById("canvas") + var ctx = canvas.getContext("2d") + + var maxW + var maxH + + var input = document.getElementById('input') + input.addEventListener('change', handleFiles) + + function handleFiles(e) { + var img = new Image + img.onload = function() { + var iw = img.width + var ih = img.height + + maxW = 800 + maxH = 800 + + var scale = Math.min((maxW/iw), (maxH/ih)) + var iwScaled = iw*scale + var ihScaled = ih*scale + canvas.width = iwScaled + canvas.height = ihScaled + ctx.drawImage(img, 0, 0, iwScaled, ihScaled) + photoURL.value = canvas.toDataURL('image/jpeg', 0.7) + } + img.src = URL.createObjectURL(e.target.files[0]) + } + } + }), + h('canvas', {id: 'canvas', width: '0', height: '0'}), + h('button', { + onclick: function () { + identifyDiv.appendChild(identifyButtons) + newBackground.parentNode.removeChild(newBackground) + } + }, ['Cancel']), + h('button', { + onclick: function () { + if (photoURL.value) { + content = { + type: 'background', + backgrounded: src, + background: photoURL.value + } + localforage.removeItem('image:' + src) + publish(content, keys).then(post => { + open(post).then(msg => { + nameInput.value = '' + scroller.insertBefore(render(msg, keys), scroller.childNodes[1]) + }) + }) + newBackground.parentNode.removeChild(newBackground) + identifyDiv.appendChild(identifyButton) + } + } + }, ['Publish']) + ]) + var newPhoto = h('span', [ h('input', {id: 'input', type: 'file', onclick: function () { @@ -47,7 +113,6 @@ function identify (src, profile, keys) { canvas.width = iwScaled canvas.height = ihScaled ctx.drawImage(img, 0, 0, iwScaled, ihScaled) - console.log(canvas.toDataURL('image/jpeg', 0.9)) photoURL.value = canvas.toDataURL('image/jpeg', 0.9) } img.src = URL.createObjectURL(e.target.files[0]) @@ -69,7 +134,6 @@ function identify (src, profile, keys) { imaged: src, image: photoURL.value } - console.log(content) localforage.removeItem('image:' + src) publish(content, keys).then(post => { open(post).then(msg => { @@ -84,6 +148,9 @@ function identify (src, profile, keys) { }, ['Publish']) ]) + + + var nameInput = h('input', {placeholder: 'New name'}) var newName = h('div', [ @@ -125,7 +192,12 @@ function identify (src, profile, keys) { identifyButtons.parentNode.removeChild(identifyButtons) } }, ['New name'])) - + identifyButtons.appendChild(h('button', { + onclick: function () { + identifyDiv.appendChild(newBackground) + identifyButtons.parentNode.removeChild(identifyButtons) + } + }, ['New background'])) } //}, ['Identify ' + src.substring(0, 10) + '... with a new name']), identifyButtons.appendChild(h('button', { diff --git a/render.js b/render.js index e440abd..faf3c17 100644 --- a/render.js +++ b/render.js @@ -183,10 +183,11 @@ function render (msg, keys, preview) { message.appendChild(buttons) } - } else if (msg.type == 'name') { + } if (msg.type == 'name') { var mini = h('span', [' identified ', h('a', {href: '#' + msg.named }, [msg.named.substring(0, 10) + '...']), ' as ' + msg.name]) message.appendChild(getHeader(msg, keys, mini)) - } else if (msg.type == 'image') { + + } if (msg.type == 'image') { var mini = h('span', [ ' added an image to ', h('a', { href: '#' + msg.imaged }, [msg.imaged.substring(0, 10) + '...']), @@ -194,8 +195,19 @@ function render (msg, keys, preview) { h('img', {src: msg.image, classList: 'avatar'}) ]) message.appendChild(getHeader(msg, keys, mini)) + + } if (msg.type == 'background') { + var mini = h('span', [ + ' added a background to ', + h('a', { href: '#' + msg.backgrounded }, [msg.backgrounded.substring(0, 10) + '...']), + ' ', + h('img', {src: msg.background, classList: 'avatar'}) + ]) + message.appendChild(getHeader(msg, keys, mini)) } + + messageDiv.appendChild(message) return messageDiv } diff --git a/views.js b/views.js index b964915..da1eeb9 100644 --- a/views.js +++ b/views.js @@ -9,7 +9,24 @@ function profilePage (src, keys) { msg.author = src var profile = h('div', {classList: 'profile'}) + var banner = h('div', {classList: 'banner'}) + + function getBg (src, profile) { + bog().then(log => { + if (log) { + for (var i = 0; i < log.length; i++) { + if ((log[i].backgrounded === src) && (log[i].author === src)) { + // if you've identified someone as something else show that something else + return banner.style.background = 'fixed top/680px no-repeat url(' + log[i].background + ')' + } + } + } + }) + } + + getBg(src, profile) + scroller.appendChild(banner) scroller.appendChild(profile) //scroller.appendChild(h('div')) @@ -27,12 +44,15 @@ function profilePage (src, keys) { profile.appendChild(h('a', {href: '#' + src}, [ getImage(src, keys, 'profileAvatar'), - getName(src, keys) + getName(src, keys), + h('br'), + h('br') ])) profile.appendChild(h('br')) quickName(src).then(name => { + profile.appendChild(identify(src, profile, keys, name)) var mentionsButton = h('button', { onclick: function () { location.href = '#?' + src @@ -76,7 +96,6 @@ function profilePage (src, keys) { }, ['Delete ' + name + '\'s feed'])) }) - profile.appendChild(identify(src, profile, keys)) async function addPosts (posts, keys) { posts.forEach(function (msg) { @@ -197,3 +216,4 @@ function publicPage (keys) { }) } + -- cgit v1.2.3-70-g09d2 From dac0064cf55e6a3f9321ea78875bfe8ca9952fc3 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 11 Jan 2020 06:13:44 -0600 Subject: finish adding backgrounds to profiles --- css/style.css | 4 ++-- gossip.js | 4 ++-- identify.js | 6 +++--- views.js | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/css/style.css b/css/style.css index df53ffe..26784e7 100644 --- a/css/style.css +++ b/css/style.css @@ -56,6 +56,8 @@ hr { .right { float: right;} +.banner {height: 10px; } + .message, .profile { border: 1px solid #ddd; background: white; @@ -67,8 +69,6 @@ hr { border-radius: 5px; } -.banner { height: 275px; } - #scroller:last-child { margin-bottom: 10em; } .message, .message > *, .navbar, .navbar > *, #ad, #ad > *, #viewer > * { diff --git a/gossip.js b/gossip.js index 5cf19e9..26915b1 100644 --- a/gossip.js +++ b/gossip.js @@ -49,7 +49,7 @@ function processreq (req, pubkey, connection, keys) { var src = window.location.hash.substring(1) if ((src === msg.author) || (src === '')) { var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[2]) + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) } if (opened.seq === req.length) { localforage.setItem('log', log) @@ -71,7 +71,7 @@ function processreq (req, pubkey, connection, keys) { var src = window.location.hash.substring(1) if ((src === msg.author) || (src === '')) { var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[2]) + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) } if (req.length + lastmsg.seq === opened.seq) { localforage.setItem('log', log) diff --git a/identify.js b/identify.js index eb8827c..f56a0f9 100644 --- a/identify.js +++ b/identify.js @@ -1,4 +1,4 @@ -function identify (src, profile, keys) { +function identify (src, profile, keys, name) { var identifyDiv = h('div') @@ -213,7 +213,6 @@ function identify (src, profile, keys) { identifyButtons.parentNode.removeChild(identifyButtons) } }, ['Cancel'])) - if (src[0] == '@') { var identifyButton = h('button', { onclick: function () { @@ -221,7 +220,7 @@ function identify (src, profile, keys) { profile.appendChild(identifyButtons) identifyButton.parentNode.removeChild(identifyButton) } - }, ['Identify ' + src.substring(0, 10) + '...']) + }, ['Identify ' + name]) } else { var identifyButton = h('button', { onclick: function () { @@ -231,6 +230,7 @@ function identify (src, profile, keys) { } }, ['Add to ' + src.substring(0, 10) + '...']) } + return identifyButton } diff --git a/views.js b/views.js index da1eeb9..d6fb5f2 100644 --- a/views.js +++ b/views.js @@ -8,6 +8,7 @@ function profilePage (src, keys) { var msg = {} msg.author = src + var profileDiv = h('div') var profile = h('div', {classList: 'profile'}) var banner = h('div', {classList: 'banner'}) @@ -16,7 +17,8 @@ function profilePage (src, keys) { if (log) { for (var i = 0; i < log.length; i++) { if ((log[i].backgrounded === src) && (log[i].author === src)) { - // if you've identified someone as something else show that something else + // if you've identified someone as something else show that something else + banner.style.height = '300px' return banner.style.background = 'fixed top/680px no-repeat url(' + log[i].background + ')' } } @@ -26,9 +28,9 @@ function profilePage (src, keys) { getBg(src, profile) - scroller.appendChild(banner) - scroller.appendChild(profile) - //scroller.appendChild(h('div')) + profileDiv.appendChild(banner) + profileDiv.appendChild(profile) + scroller.appendChild(profileDiv) var subs = [src] @@ -45,8 +47,6 @@ function profilePage (src, keys) { profile.appendChild(h('a', {href: '#' + src}, [ getImage(src, keys, 'profileAvatar'), getName(src, keys), - h('br'), - h('br') ])) profile.appendChild(h('br')) -- cgit v1.2.3-70-g09d2 From 2995dfc6982846494f493a5eb1dc7ffc2e3687c1 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 11 Jan 2020 07:43:32 -0600 Subject: finish adding backgrounds --- css/style.css | 2 +- identify.js | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- render.js | 20 ++++++++++++- views.js | 92 +++++++++++++++++++++++++++++++++++++++++------------------ 4 files changed, 169 insertions(+), 34 deletions(-) diff --git a/css/style.css b/css/style.css index 26784e7..cfa5012 100644 --- a/css/style.css +++ b/css/style.css @@ -240,7 +240,7 @@ form.search { text-decoration: none; } -.profileAvatar { width: 75px; vertical-align: top; border-radius: 5px; object-fit: cover; margin-right: .25em; margin-bottom: .25em;} +.profileAvatar { width: 95px; height: 95px; vertical-align: top; border-radius: 5px; object-fit: cover; margin-right: .25em; margin-bottom: .25em;} .avatar { width: 25px; height: 25px; vertical-align: middle; object-fit: cover; border-radius: 5px; margin-right: .5em; } .image { width: 75px; height: 75px; object-fit: cover; margin-right: .2em; border-radius: 5px; cursor: pointer;} diff --git a/identify.js b/identify.js index f56a0f9..acda8c8 100644 --- a/identify.js +++ b/identify.js @@ -3,7 +3,10 @@ function identify (src, profile, keys, name) { var identifyDiv = h('div') if ((src[0] == '@') && (src != keys.publicKey)) { - identifyDiv.appendChild(h('p', ['Please note: ' + src + ' is not you.'])) + identifyDiv.appendChild(h('p', [ + 'Please note: ' + src.substring(0, 10) + '... is not you. You are: ', + h('a', {href: '#' + keys.publicKey}, [keys.publicKey.substring(0, 10) + '...']) + ])) } var photoURL = {} @@ -148,8 +151,67 @@ function identify (src, profile, keys, name) { }, ['Publish']) ]) + var descInput = h('textarea', {placeholder: 'New description'}) + var newDescription = h('div', [ + descInput, + h('button', { + onclick: function () { + if (descInput.value) { + content = { + type: 'description', + descripted: src, + description: descInput.value + } + publish(content, keys).then(post => { + open(post).then(msg => { + descInput.value = '' + scroller.insertBefore(render(msg, keys), scroller.childNodes[1]) + }) + }) + newDescription.parentNode.removeChild(newDescription) + identifyDiv.appendChild(identifyButton) + } + } + }, ['Publish']), + h('button', { + onclick: function () { + identifyDiv.appendChild(identifyButtons) + newDescription.parentNode.removeChild(newDescription) + } + }, ['Cancel']) + ]) + var locInput = h('input', {placeholder: 'New location'}) + + var newLocation = h('div', [ + locInput, + h('button', { + onclick: function () { + if (locInput.value) { + content = { + type: 'location', + located: src, + loc: locInput.value + } + publish(content, keys).then(post => { + open(post).then(msg => { + locationInput.value = '' + scroller.insertBefore(render(msg, keys), scroller.childNodes[1]) + }) + }) + newLocation.parentNode.removeChild(newLocation) + identifyDiv.appendChild(identifyButton) + } + } + }, ['Publish']), + h('button', { + onclick: function () { + identifyDiv.appendChild(identifyButtons) + newLocation.parentNode.removeChild(newLocation) + } + }, ['Cancel']) + ]) var nameInput = h('input', {placeholder: 'New name'}) @@ -198,6 +260,13 @@ function identify (src, profile, keys, name) { identifyButtons.parentNode.removeChild(identifyButtons) } }, ['New background'])) + identifyButtons.appendChild(h('button', { + onclick: function () { + identifyDiv.appendChild(newDescription) + identifyButtons.parentNode.removeChild(identifyButtons) + } + }, ['New description'])) + } //}, ['Identify ' + src.substring(0, 10) + '... with a new name']), identifyButtons.appendChild(h('button', { @@ -206,6 +275,15 @@ function identify (src, profile, keys, name) { identifyButtons.parentNode.removeChild(identifyButtons) } }, ['New image'])) + + identifyButtons.appendChild(h('button', { + onclick: function () { + identifyDiv.appendChild(newLocation) + identifyButtons.parentNode.removeChild(identifyButtons) + } + }, ['New location'])) + + //}, ['Identify ' + src.substring(0, 10) + '... with a new photo']), identifyButtons.appendChild(h('button', { onclick: function () { @@ -213,7 +291,7 @@ function identify (src, profile, keys, name) { identifyButtons.parentNode.removeChild(identifyButtons) } }, ['Cancel'])) - if (src[0] == '@') { + /*if (src[0] == '@') { var identifyButton = h('button', { onclick: function () { profile.appendChild(identifyDiv) @@ -221,15 +299,16 @@ function identify (src, profile, keys, name) { identifyButton.parentNode.removeChild(identifyButton) } }, ['Identify ' + name]) - } else { + } else { */ var identifyButton = h('button', { onclick: function () { profile.appendChild(identifyDiv) profile.appendChild(identifyButtons) identifyButton.parentNode.removeChild(identifyButton) } - }, ['Add to ' + src.substring(0, 10) + '...']) - } + //}, ['Add to ' + src.substring(0, 10) + '...']) + }, ['+']) + //} return identifyButton } diff --git a/render.js b/render.js index faf3c17..5ecbdda 100644 --- a/render.js +++ b/render.js @@ -15,6 +15,8 @@ function getHeader (post, keys, mini) { var head = h('span', [ h('p', {classList: 'right'}, [ + getLoc(post), + ' ', h('a', {href: '#' + post.key}, [ human(new Date(post.timestamp)), ]), @@ -204,9 +206,25 @@ function render (msg, keys, preview) { h('img', {src: msg.background, classList: 'avatar'}) ]) message.appendChild(getHeader(msg, keys, mini)) - } + } if (msg.type == 'description') { + var mini = h('span', [ + ' added a description to ', + h('a', { href: '#' + msg.descripted }, [msg.descripted.substring(0, 10) + '...']), + ' ', + h('div', {innerHTML: marked(msg.description)}) + ]) + message.appendChild(getHeader(msg, keys, mini)) + } if (msg.type == 'location') { + var mini = h('span', [ + ' added a location to ', + h('a', { href: '#' + msg.located }, [msg.located.substring(0, 10) + '...']), + ': ', + msg.loc + ]) + message.appendChild(getHeader(msg, keys, mini)) + } messageDiv.appendChild(message) return messageDiv diff --git a/views.js b/views.js index d6fb5f2..f98b88c 100644 --- a/views.js +++ b/views.js @@ -4,7 +4,36 @@ function threadPage (src, keys) { }) } +function getLoc (src) { + var loc = h('span') + bog().then(log => { + if (log) { + for (var i = 0; i < log.length; i++) { + if (((log[i].located === src) && (log[i].author === src)) || ((log[i].located === src.key) && (log[i].author === src.author))) { + // if you've identified someone as something else show that something else + return loc.textContent = log[i].loc + } + } + } + }) + return loc +} + + function profilePage (src, keys) { + + var interval = 500 + + timer = function() { + if (src === window.location.hash.substring(1)) { + if (interval < 10000) { interval = interval + 50 } + sync([src], keys) + setTimeout(timer, interval) + } + } + + timer() + var msg = {} msg.author = src @@ -12,6 +41,21 @@ function profilePage (src, keys) { var profile = h('div', {classList: 'profile'}) var banner = h('div', {classList: 'banner'}) + function getDesc (src) { + var desc = h('span') + bog().then(log => { + if (log) { + for (var i = 0; i < log.length; i++) { + if ((log[i].descripted === src) && (log[i].author === src)) { + // if you've identified someone as something else show that something else + return desc.innerHTML = marked(log[i].description) + } + } + } + }) + return desc + } + function getBg (src, profile) { bog().then(log => { if (log) { @@ -26,33 +70,23 @@ function profilePage (src, keys) { }) } + getBg(src, profile) profileDiv.appendChild(banner) profileDiv.appendChild(profile) scroller.appendChild(profileDiv) - var subs = [src] - - var interval = 2500 - timer = function() { - if (src === window.location.hash.substring(1)) { - if (interval < 10000) { interval = interval + 50 } - sync(subs, keys) - setTimeout(timer, interval) - } - } - timer() - - profile.appendChild(h('a', {href: '#' + src}, [ - getImage(src, keys, 'profileAvatar'), - getName(src, keys), + profile.appendChild(h('span', {classList: 'right'}, [getLoc(src)])) + profile.appendChild(h('div', [ + h('a', {href: '#' + src}, [ + getImage(src, keys, 'profileAvatar'), + getName(src, keys) + ]), + profile.appendChild(getDesc(src)) ])) - profile.appendChild(h('br')) - quickName(src).then(name => { - profile.appendChild(identify(src, profile, keys, name)) var mentionsButton = h('button', { onclick: function () { location.href = '#?' + src @@ -66,6 +100,15 @@ function profilePage (src, keys) { }, ['Reply to ' + name]) profile.appendChild(respond) + profile.appendChild(h('button', { + onclick: function () { + localforage.removeItem(src).then(function () { + var home = true + regenerate(home) + }) + } + }, ['Delete ' + name + '\'s feed'])) + if (src != keys.publicKey) { localforage.getItem('subscriptions').then(function (subs) { if (subs.includes(src)) { @@ -83,17 +126,12 @@ function profilePage (src, keys) { } }, ['Subscribe to ' + name])) } + profile.appendChild(identify(src, profile, keys)) }) + } else { + profile.appendChild(identify(src, profile, keys)) } - - profile.appendChild(h('button', { - onclick: function () { - localforage.removeItem(src).then(function () { - var home = true - regenerate(home) - }) - } - }, ['Delete ' + name + '\'s feed'])) + //profile.appendChild(identify(src, profile, keys, name)) }) -- cgit v1.2.3-70-g09d2 From c751bc988ad88c20f3bd64381cd782af0182d8b1 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 11 Jan 2020 07:58:58 -0600 Subject: accurately send the last few posts --- server.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 15135c0..b8d2262 100644 --- a/server.js +++ b/server.js @@ -133,8 +133,9 @@ bog.keys().then(key => { } if (unboxedreq.seq < msg.seq) { var endrange = feed.length - unboxedreq.seq - Math.floor(Math.random() * 50 + 1) + console.log(endrange) if (endrange < 0) { - endrange = feed.length - unboxedreq.seq - 1 + endrange = 0 } var baserange = feed.length - unboxedreq.seq printClientShorter(msg, req, baserange, endrange) -- cgit v1.2.3-70-g09d2 From dccfda7a227fdcf834a3b5e167f30af53e6c6507 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 11 Jan 2020 08:23:10 -0600 Subject: remove console.log --- server.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server.js b/server.js index b8d2262..c1632f0 100644 --- a/server.js +++ b/server.js @@ -133,7 +133,6 @@ bog.keys().then(key => { } if (unboxedreq.seq < msg.seq) { var endrange = feed.length - unboxedreq.seq - Math.floor(Math.random() * 50 + 1) - console.log(endrange) if (endrange < 0) { endrange = 0 } -- cgit v1.2.3-70-g09d2 From bca1b99d3a844c7ed6b956be20b026dd3666b188 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 11 Jan 2020 11:10:20 -0600 Subject: this seems to improve sync speed --- server.js | 8 +++++++- settings.js | 4 ++-- views.js | 48 ++++++++++++++++++++++++++---------------------- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/server.js b/server.js index c1632f0..b022ac0 100644 --- a/server.js +++ b/server.js @@ -105,8 +105,10 @@ bog.keys().then(key => { wserve.on('connection', function (ws) { ws.on('message', function (message) { var req = JSON.parse(message) + console.log(req) if (req.sendpub) { ws.send(key.publicKey) + ws.close() } else { bog.unbox(req.box, req.requester, key).then(unboxed => { var unboxedreq = JSON.parse(unboxed) @@ -119,7 +121,8 @@ bog.keys().then(key => { bog.open(feed[0]).then(msg => { if (unboxedreq.seq === msg.seq) { printFeedIdentical(msg, req) - } + ws.close() + } if (unboxedreq.seq > msg.seq) { printClientLonger(msg, req) var reqdiff = JSON.stringify({author: unboxedreq.author, seq: msg.seq}) @@ -129,6 +132,7 @@ bog.keys().then(key => { box: boxed } ws.send(JSON.stringify(obj)) + ws.close() }) } if (unboxedreq.seq < msg.seq) { @@ -163,6 +167,7 @@ bog.keys().then(key => { box: boxed } ws.send(JSON.stringify(obj)) + ws.close() }) } }) @@ -182,6 +187,7 @@ bog.keys().then(key => { printUpdateFeed(msg, req) }) } + ws.close() }) }) } diff --git a/settings.js b/settings.js index b0cb561..9a20dc3 100644 --- a/settings.js +++ b/settings.js @@ -63,7 +63,7 @@ function settingsPage (keys) { onclick: function () { if (add.value) { servers.push(add.value) - localforage.setItem('pubs', servers).then(function () { location.reload() }) + localforage.setItem('pubs', servers).then(function () { location.hash = '' }) } } }, ['Add a pub']) @@ -75,7 +75,7 @@ function settingsPage (keys) { h('button', { onclick: function () { var newServers = servers.filter(item => item !== pub) - localforage.setItem('pubs', newServers).then(function () { location.reload() }) + localforage.setItem('pubs', newServers).then(function () { location.hash = '' }) } }, ['Remove']) ])) diff --git a/views.js b/views.js index f98b88c..86f6067 100644 --- a/views.js +++ b/views.js @@ -19,20 +19,26 @@ function getLoc (src) { return loc } - function profilePage (src, keys) { - var interval = 500 + var timer = setInterval(function () { + if (window.location.hash.substring(1) != src) { + clearInterval(timer) + console.log('stop syncing') + } + sync([src], keys) + console.log('syncing ' + src) + }, 2500) - timer = function() { + /*timer = function() { if (src === window.location.hash.substring(1)) { - if (interval < 10000) { interval = interval + 50 } + //if (interval < 10000) { interval = interval + 50 } sync([src], keys) setTimeout(timer, interval) } } - timer() + timer()*/ var msg = {} msg.author = src @@ -70,7 +76,6 @@ function profilePage (src, keys) { }) } - getBg(src, profile) profileDiv.appendChild(banner) @@ -115,14 +120,14 @@ function profilePage (src, keys) { profile.appendChild(h('button', { onclick: function () { subs = subs.filter(a => a !== src) - localforage.setItem('subscriptions', subs).then(function () { location.reload() }) + localforage.setItem('subscriptions', subs).then(function () { location.hash = '' }) } }, ['Unsubscribe from ' + name])) } else { profile.appendChild(h('button', { onclick: function () { subs.push(src) - localforage.setItem('subscriptions', subs).then(function () { location.reload() }) + localforage.setItem('subscriptions', subs).then(function () { location.hash = '' }) } }, ['Subscribe to ' + name])) } @@ -164,7 +169,6 @@ function profilePage (src, keys) { function searchPage (src, keys) { var search = src.substring(1).replace("%20"," ").toUpperCase() - async function addPosts (posts, keys) { posts.forEach(function (msg) { if (msg.text) { @@ -202,28 +206,30 @@ function publicPage (keys) { }) localforage.getItem('subscriptions').then(subs => { - var interval = 1000 - timer = function() { - if ('' === window.location.hash.substring(1)) { - if (interval < 10000) { interval = interval + 1000 } - sync(subs, keys) - setTimeout(timer, interval) - } - } if (subs) { // the next two lines just fix a bug where the first sub was being set to null. Delete this code after March 2020. - subs.forEach(sub => { + + subs.forEach(function (sub, index) { + var timer = setInterval(function () { + setTimeout(function () { + if (window.location.hash.substring(1) != '') { + clearInterval(timer) + console.log('stop syncing') + } + sync([sub], keys) + console.log('syncing ' + sub) + }, 1000 * index) + }, 2500) + if (sub == null) { var subs = [keys.publicKey] localforage.setItem('subscriptions', subs) } }) - timer() } else { var subs = [keys.publicKey] console.log(subs) localforage.setItem('subscriptions', subs) - timer() } }) @@ -253,5 +259,3 @@ function publicPage (keys) { } }) } - - -- cgit v1.2.3-70-g09d2 From c561c03eaac6d6719d5a4d7f5be5d281ef01b54d Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 11 Jan 2020 11:14:33 -0600 Subject: remove log --- server.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server.js b/server.js index b022ac0..ea2c8f6 100644 --- a/server.js +++ b/server.js @@ -105,7 +105,6 @@ bog.keys().then(key => { wserve.on('connection', function (ws) { ws.on('message', function (message) { var req = JSON.parse(message) - console.log(req) if (req.sendpub) { ws.send(key.publicKey) ws.close() -- cgit v1.2.3-70-g09d2 From d70d9dc649b217cc1da5e0c17e25570606085cda Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 11 Jan 2020 11:33:35 -0600 Subject: try fixing the sub == undefined bug again --- views.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views.js b/views.js index 86f6067..1cfe338 100644 --- a/views.js +++ b/views.js @@ -221,7 +221,7 @@ function publicPage (keys) { }, 1000 * index) }, 2500) - if (sub == null) { + if ((sub == null) || (sub == undefined)) { var subs = [keys.publicKey] localforage.setItem('subscriptions', subs) } -- cgit v1.2.3-70-g09d2 From 3f43899f39178365e42e7cd906b017f7e752295a Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 12 Jan 2020 07:19:01 -0600 Subject: fix distance between first post and navbar --- css/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css/style.css b/css/style.css index cfa5012..135970e 100644 --- a/css/style.css +++ b/css/style.css @@ -61,11 +61,11 @@ hr { .message, .profile { border: 1px solid #ddd; background: white; - margin-bottom: .5em; padding: .3em .5em; } .message { + margin-top: .5em; border-radius: 5px; } -- cgit v1.2.3-70-g09d2 From 87ad0e1126377cbe876f654b00da4ec546dc7d43 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 12 Jan 2020 12:28:18 -0600 Subject: fill out settings page with more information, and add a link to a video --- settings.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/settings.js b/settings.js index 9a20dc3..889e0ea 100644 --- a/settings.js +++ b/settings.js @@ -1,11 +1,13 @@ function settingsPage (keys) { var welcome = h('div', {classList: 'message'}) - welcome.appendChild(h('p', {innerHTML: marked('This is [Bogbook](http://bogbook.com), a distributed social network built using secure-gossiped blockchain logging (blogging), but we call them "bogs".\n\n You can view the code at [git.sr.ht/~ev/bogbook](https://git.sr.ht/~ev/bogbook) or clone it directly from our server:\n```\ngit clone http://git.bogbook.com/bogbook.git\n```\n Please communicate errors, bugs, and pull-requests to [@ev](http://bogbook.com/#@Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0=) using Bogbook or via email: [ev@evbogue.com](mailto:ev@evbogue.com)')})) + welcome.appendChild(h('p', {innerHTML: marked('### About Bogbook \n\n[Bogbook](http://bogbook.com) is a distributed social network built using secure-gossiped blockchain logging (blogging), but we call them "bogs".\n\n With bogbook you can create your own secure social network that is easily replicated between browsers via bogbook pubs.\n\n To try bogbook, type a message into the [compose box](/) on the bogbook instance you are using, then press preview and publish.\n\n You can view the bogbook code at [git.sr.ht/~ev/bogbook](https://git.sr.ht/~ev/bogbook) or clone it directly from our server:\n```\ngit clone http://git.bogbook.com/bogbook.git\n```\n Please communicate errors, bugs, and pull-requests to [@ev](http://bogbook.com/#@Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0=) using Bogbook or via email: [ev@evbogue.com](mailto:ev@evbogue.com)\n\n Here\'s a video of Bogbook in the early days:')})) + + welcome.appendChild(h('div', {innerHTML: ''})) var keyDiv = h('div', {classList: 'message'}) - keyDiv.appendChild(h('p', {innerHTML: marked('This is your ed25519 public/private keypair. It was generated using [TweetNaCl.js](https://tweetnacl.js.org/#/). Your public key is your identity when using Bogbook, save your key in a safe place so that you can continue to use the same identity.')})) + keyDiv.appendChild(h('p', {innerHTML: marked('### Your keypair \n\n This is your ed25519 public/private keypair. It was generated using [TweetNaCl.js](https://tweetnacl.js.org/#/). \n\n Bogbook does not use logins and passwords, instead you are able to post by signing messages with your keypair. \n\n Because Bogbook uses keypairs for identities, as long as your private key is safe no one can post to your feed (or delete your posts) without your permission. \n\n**Save your key** in a safe place so that you can continue to use the same identity.')})) keyDiv.appendChild(h('pre', {style: 'width: 80%'}, [h('code', [JSON.stringify(keys)])])) @@ -30,7 +32,7 @@ function settingsPage (keys) { var everything = h('div', {classList: 'message'}) - everything.appendChild(h('p', {innerHTML: marked('Sometimes you may want to delete all of your bogbook data in the browser. When you click this button, Bogbook will erase everything that you\'ve stored in the browser. NOTE: This will not delete Bogbook posts that you have already gossiped with others. WARNING: This will delete your Bogbook keypair as well as all data stored in the browser. If you want to continue to use the same key, make sure you\'ve backed up your keypair!')})) + everything.appendChild(h('p', {innerHTML: marked('### Delete everything \n\n Sometimes you may want to delete all of your bogbook data in the browser. When you click this button, Bogbook will erase everything that you\'ve stored in the browser.\n\n **NOTE**: This will not delete Bogbook posts that you have already gossiped with others.\n\n **WARNING**: This will delete your Bogbook keypair as well as all data stored in the browser. If you want to continue to use the same key, make sure you\'ve backed up your keypair!')})) everything.appendChild(h('button', { onclick: function () { @@ -52,7 +54,7 @@ function settingsPage (keys) { var pubs = h('div', {classList: 'message'}) - pubs.appendChild(h('p', {innerHTML: marked('These are your bogbook pubs. Bogbook will gossip with these pubs to publish your messages and check for new messages from your subscriptions. You should have at least one Bogbook pub in order to gossip your messages. If you don\'t see a bogbook pub below, try clicking "Reset Pubs" or add \n```\nws://bogbook.com\n```\n to your pubs list.')})) + pubs.appendChild(h('p', {innerHTML: marked('### Bogbook Pubs \n\n These are your bogbook pubs. Bogbook will gossip with these pubs to publish your messages and check for new messages from your subscriptions. You should have at least one Bogbook pub in order to gossip your messages. If you don\'t see a bogbook pub below, try clicking "Reset Pubs" or add \n```\nws://bogbook.com\n```\n to your pubs list.')})) var add = h('input', {placeholder: 'Add a pub'}) @@ -91,10 +93,10 @@ function settingsPage (keys) { } }, ['Reset pubs'])) - scroller.appendChild(welcome) scroller.appendChild(keyDiv) scroller.appendChild(pubs) scroller.appendChild(everything) + scroller.appendChild(welcome) //scroller.appendChild(regenerate) } -- cgit v1.2.3-70-g09d2 From 8abaa0d61941a8cbb25aa16efda712d17ca2d9c2 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 12 Jan 2020 12:32:35 -0600 Subject: grammar and add a link to ed25519 --- settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.js b/settings.js index 889e0ea..3c175b3 100644 --- a/settings.js +++ b/settings.js @@ -7,7 +7,7 @@ function settingsPage (keys) { var keyDiv = h('div', {classList: 'message'}) - keyDiv.appendChild(h('p', {innerHTML: marked('### Your keypair \n\n This is your ed25519 public/private keypair. It was generated using [TweetNaCl.js](https://tweetnacl.js.org/#/). \n\n Bogbook does not use logins and passwords, instead you are able to post by signing messages with your keypair. \n\n Because Bogbook uses keypairs for identities, as long as your private key is safe no one can post to your feed (or delete your posts) without your permission. \n\n**Save your key** in a safe place so that you can continue to use the same identity.')})) + keyDiv.appendChild(h('p', {innerHTML: marked('### Your keypair \n\n This is your [ed25519](https://ed25519.cr.yp.to/) keypair. It was generated using [TweetNaCl.js](https://tweetnacl.js.org/#/). \n\n Bogbook does not use logins and passwords, instead you are able to post by signing messages with your keypair. \n\n Because Bogbook uses keypairs for identities, keep your keypair safe so no one can post to your feed (or delete your posts) without your permission. \n\n**Save your key** in a safe place so that you can continue to use the same identity.')})) keyDiv.appendChild(h('pre', {style: 'width: 80%'}, [h('code', [JSON.stringify(keys)])])) -- cgit v1.2.3-70-g09d2 From 613dc7147bc68e1065f0d084cc8ed089680b49fd Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 17 Jan 2020 10:05:20 -0600 Subject: avoid closing connection before receiving diff --- server.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index ea2c8f6..a73f5ad 100644 --- a/server.js +++ b/server.js @@ -131,7 +131,6 @@ bog.keys().then(key => { box: boxed } ws.send(JSON.stringify(obj)) - ws.close() }) } if (unboxedreq.seq < msg.seq) { @@ -141,11 +140,23 @@ 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)) + }) var diff = JSON.stringify( feed.slice( endrange, - baserange) + baserange ) + ) bog.box(diff, req.requester, key).then(boxed => { var obj = { requester: key.publicKey, @@ -166,7 +177,6 @@ bog.keys().then(key => { box: boxed } ws.send(JSON.stringify(obj)) - ws.close() }) } }) -- cgit v1.2.3-70-g09d2 From 970777008147f611bef649ac1d682c8f9e3a44fa Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 19 Jan 2020 09:20:23 -0600 Subject: send latest five posts if the feed has many unsynced messages, render latest in the client if we are not caught up --- gossip.js | 37 +++++++++++++++++++++++++++++++++++++ server.js | 26 +++++++++++++++----------- views.js | 2 +- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/gossip.js b/gossip.js index 26915b1..a67ea3c 100644 --- a/gossip.js +++ b/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 => { diff --git a/server.js b/server.js index a73f5ad..dd75528 100644 --- a/server.js +++ b/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, diff --git a/views.js b/views.js index 1cfe338..1878b3c 100644 --- a/views.js +++ b/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)) { -- cgit v1.2.3-70-g09d2 From 7a5291fd24326b799db92fc4f15c49111ab7c172 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 19 Jan 2020 09:22:14 -0600 Subject: comment out console logs --- gossip.js | 6 +++--- server.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gossip.js b/gossip.js index a67ea3c..be16a9c 100644 --- a/gossip.js +++ b/gossip.js @@ -59,16 +59,16 @@ function processreq (req, pubkey, connection, keys) { if (msg.seq >= latestmsg.seq) { latest.parentNode.removeChild(latest) clearInterval(timer) - console.log('we are caught up, deleting latest div') + //console.log('we are caught up, deleting latest div') } if (src != req.latest) { clearInterval(timer) - console.log('we navigated away') + //console.log('we navigated away') } }) }) }) - console.log('checking to see if we have caught up') + //console.log('checking to see if we have caught up') }, 5000) } } diff --git a/server.js b/server.js index dd75528..9a53943 100644 --- a/server.js +++ b/server.js @@ -150,7 +150,7 @@ bog.keys().then(key => { requester: key.publicKey, box: boxed } - console.log('sending latest ' + unboxedreq.author) + //console.log('sending latest ' + unboxedreq.author) ws.send(JSON.stringify(obj)) }) } -- cgit v1.2.3-70-g09d2 From 1833a4ad443e15863afc979eb9a63473102d0f79 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 19 Jan 2020 12:14:05 -0600 Subject: add namespace redirect (ex: http://bogbook.com/ev) --- server.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/server.js b/server.js index 9a53943..a4f563f 100644 --- a/server.js +++ b/server.js @@ -86,6 +86,31 @@ var open = require('open') var app = new koa() +// namespace redirect -- add namespaces to ~/.bogbook/names.json +app.use(async function (ctx, next) { + if (ctx.request.url[1] != '#') { + var name = ctx.request.url.substring(1) + + if (!fs.existsSync(path + 'names.json')) { + var obj = { + ev: '@Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0=', + mil3s: '@531mT2x1FnQdpYJxVrG8YD9wiE767xO88kKRhi5A3Yg=', + g: '@WVBPY53Bl4aUIngt2TXV8nW+IGKvCTqhv88EvktOX9s=' + } + fs.writeFileSync(path + 'names.json', JSON.stringify(obj), 'UTF-8') + } + + var obj = JSON.parse(fs.readFileSync(path + 'names.json', 'UTF-8')) + + for (var property in obj) { + if ((name === property) || (name === property + '/')) { + ctx.redirect('/#' + obj[property]) + } + } + } + return await next() +}) + app.use(serve({rootDir: '.', notFoundFile: 'index.html'})) app.listen(config.port) -- cgit v1.2.3-70-g09d2 From b7cbdc9c3c0e2feb4da24faaad343e5433d8fd9b Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Wed, 22 Jan 2020 13:26:26 -0600 Subject: fix avatar cache to speed up image/name load time --- bog.js | 91 +++++++++++++++++++++++++++++++++++---------------------------- render.js | 4 +-- 2 files changed, 52 insertions(+), 43 deletions(-) diff --git a/bog.js b/bog.js index d8ee2a8..2170216 100644 --- a/bog.js +++ b/bog.js @@ -115,28 +115,20 @@ function getImage (id, keys, classList) { var image = h('img', {classList: 'avatar'}) } - localforage.getItem('image:' + id).then(cache => { - //if (cache) { - // return image.src = cache - //} else { - bog().then(log => { - if (log) { - for (var i = 0; i < log.length; i++) { - if ((log[i].imaged === id) && (log[i].author === keys.publicKey)) { - // if you've identified someone as something else show that something else - localforage.setItem('image:' + id, log[i].image) - image.src = cache - return image.src = cache - } else if ((log[i].imaged === id) && (log[i].author === id)) { - // else if show the image they gave themselves - localforage.setItem('image:' + id, log[i].image) - image.src = cache - return image.src = cache - } - } + bog().then(log => { + if (log) { + for (var i = 0; i < log.length; i++) { + if ((log[i].imaged === id) && (log[i].author === keys.publicKey)) { + // if you've identified someone as something else show that something else + localforage.setItem('image:' + id, log[i].image) + return image.src = log[i].image + } else if ((log[i].imaged === id) && (log[i].author === id)) { + // else if show the image they gave themselves + localforage.setItem('image:' + id, log[i].image) + return image.src = log[i].image } - }) - //} + } + } }) return image } @@ -148,29 +140,46 @@ function getName (id, keys) { name.textContent = id.substring(0, 10) + '...' - localforage.getItem('name:' + id).then(cache => { + bog().then(log => { + if (log) { + for (var i = 0; i < log.length; i++ ) { + if ((log[i].named === id) && (log[i].author === keys.publicKey)) { + // if you've identified someone as something else show that something else + localforage.setItem('name:' + id, log[i].name) + return name.textContent = '@' + log[i].name + } else if ((log[i].named === id) && (log[i].author === id)) { + // else if show the name they gave themselves + localforage.setItem('name:' + id, log[i].name) + return name.textContent = '@' + log[i].name + } + // there should probably be some sort of sybil attack resiliance here (weight avatar name based on number of times used by individuals), but this will do for now. + } + } + }) + return name +} + +function getQuickImage (id, keys) { + var image = h('img', {classList: 'avatar'}) + + localforage.getItem('image:' + id).then(cache => { if (cache) { - //console.log(cache) - return name.textContent = '@' + cache - } else { - bog().then(log => { - if (log) { - for (var i = 0; i < log.length; i++ ) { - if ((log[i].named === id) && (log[i].author === keys.publicKey)) { - // if you've identified someone as something else show that something else - localforage.setItem('name:' + id, log[i].name) - return name.textContent = '@' + log[i].name - } else if ((log[i].named === id) && (log[i].author === id)) { - // else if show the name they gave themselves - localforage.setItem('name:' + id, log[i].name) - return name.textContent = '@' + log[i].name - } - // there should probably be some sort of sybil attack resiliance here (weight avatar name based on number of times used by individuals), but this will do for now. - } - } - }) + image.src = cache } }) + + return image +} + +function getQuickName (id, keys) { + var name = h('span', [id.substring(0, 10)]) + + localforage.getItem('name:' + id).then(cache => { + if (cache) { + name.textContent = '@' + cache + } + }) + return name } diff --git a/render.js b/render.js index 5ecbdda..326f02e 100644 --- a/render.js +++ b/render.js @@ -25,8 +25,8 @@ function getHeader (post, keys, mini) { ]), h('p', [ h('a', {href: '#' + post.author}, [ - getImage(post.author, keys), - getName(post.author, keys) + getQuickImage(post.author, keys), + getQuickName(post.author, keys) ]), mini ]) -- cgit v1.2.3-70-g09d2 From cf84b3234e9856c5dbf0d25fdcbc4c227d4325cc Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 25 Jan 2020 16:02:53 -0600 Subject: make added image link to post --- render.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/render.js b/render.js index 326f02e..193201b 100644 --- a/render.js +++ b/render.js @@ -192,9 +192,11 @@ function render (msg, keys, preview) { } if (msg.type == 'image') { var mini = h('span', [ ' added an image to ', - h('a', { href: '#' + msg.imaged }, [msg.imaged.substring(0, 10) + '...']), - ' ', - h('img', {src: msg.image, classList: 'avatar'}) + h('a', { href: '#' + msg.imaged }, [ + msg.imaged.substring(0, 10) + '...', + ' ', + h('img', {src: msg.image, classList: 'avatar'}) + ]) ]) message.appendChild(getHeader(msg, keys, mini)) -- cgit v1.2.3-70-g09d2 From 16d261f8a2cb44d5364f5a993b800664236f4318 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 25 Jan 2020 16:03:17 -0600 Subject: predictive scrolling --- views.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/views.js b/views.js index 1878b3c..f4b5569 100644 --- a/views.js +++ b/views.js @@ -150,13 +150,14 @@ function profilePage (src, keys) { bog().then(log => { var index = 0 if (log) { - var posts = log.slice(index, index + 25) + var posts = log.slice(index, index + 33) addPosts(posts, keys).then(done => { - index = index + 25 + index = index + 33 window.onscroll = function(ev) { - if (((window.innerHeight + window.scrollY) >= document.body.scrollHeight) && (window.location.hash.substring(1) === src)) { - posts = log.slice(index, index + 25) - index = index + 25 + console.log(document.body.scrollHeight) + if (((window.innerHeight + window.scrollY) >= (document.body.scrollHeight - 2500)) && (window.location.hash.substring(1) === src)) { + posts = log.slice(index, index + 33) + index = index + 33 addPosts(posts, keys) console.log("Bottom of page") } -- cgit v1.2.3-70-g09d2 From 078d3661e62e1dc87449aca8cabbf728b27ab89e Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 26 Jan 2020 09:46:00 -0600 Subject: predictive scrolling everywhere, remove logs --- views.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/views.js b/views.js index f4b5569..85f45c4 100644 --- a/views.js +++ b/views.js @@ -24,10 +24,10 @@ function profilePage (src, keys) { var timer = setInterval(function () { if (window.location.hash.substring(1) != src) { clearInterval(timer) - console.log('stop syncing') + //console.log('stop syncing') } sync([src], keys) - console.log('syncing ' + src) + //console.log('syncing ' + src) }, 5000) /*timer = function() { @@ -154,12 +154,12 @@ function profilePage (src, keys) { addPosts(posts, keys).then(done => { index = index + 33 window.onscroll = function(ev) { - console.log(document.body.scrollHeight) + //console.log(document.body.scrollHeight) if (((window.innerHeight + window.scrollY) >= (document.body.scrollHeight - 2500)) && (window.location.hash.substring(1) === src)) { posts = log.slice(index, index + 33) index = index + 33 addPosts(posts, keys) - console.log("Bottom of page") + //console.log("Bottom of page") } } }) @@ -182,15 +182,15 @@ function searchPage (src, keys) { bog().then(log => { var index = 0 if (log) { - var posts = log.slice(index, index + 25) + var posts = log.slice(index, index + 33) addPosts(posts, keys).then(done => { - index = index + 25 + index = index + 33 window.onscroll = function(ev) { - if (((window.innerHeight + window.scrollY) >= document.body.scrollHeight) && (window.location.hash.substring(1) === src)) { - posts = log.slice(index, index + 25) - index = index + 25 + if (((window.innerHeight + window.scrollY) >= document.body.scrollHeight - 2500) && (window.location.hash.substring(1) === src)) { + posts = log.slice(index, index + 33) + index = index + 33 addPosts(posts, keys) - console.log("Bottom of page") + //console.log("Bottom of page") } } }) @@ -215,10 +215,10 @@ function publicPage (keys) { setTimeout(function () { if (window.location.hash.substring(1) != '') { clearInterval(timer) - console.log('stop syncing') + //console.log('stop syncing') } sync([sub], keys) - console.log('syncing ' + sub) + //console.log('syncing ' + sub) }, 1000 * index) }, 2500) -- cgit v1.2.3-70-g09d2 From f74774f6346fa4a454237386d80216992c4b79f9 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 26 Jan 2020 10:17:31 -0600 Subject: add hashtag support to posts --- render.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/render.js b/render.js index 193201b..4e16168 100644 --- a/render.js +++ b/render.js @@ -85,14 +85,38 @@ function render (msg, keys, preview) { } }) - message.insertBefore(img, message.childNodes[message.childNodes.length - 1]) + message.insertBefore(img, message.childNodes[message.childNodes.length - 1]) } }) } }) var renderer = new marked.Renderer(); - renderer.link = function(href, title, text) { + renderer.paragraph = function (paragraph) { + var array = paragraph.split(' ') + + for (i = 0; i < array.length; i++) { + word = array[i] + if (word.startsWith('#')) { + //console.log(word + ' is a hashtag') + if ((word[word.length -1] === '.') || word[word.length - 1] === ',') { + //console.log('and it ends with a ' + word[word.length - 1]) + var end = word[word.length - 1] + word = word.substring(0, word.length - 1) + } + var hashtag = "" + word + "" + if (end) { + hashtag = hashtag + end + } + //console.log(hashtag) + array[i] = hashtag + } + } + + paragraph = array.join(' ') + return paragraph + } + renderer.link = function (href, title, text) { if ((href[0] == '@') || (href[0] == '%')) { href = '#' + href } -- cgit v1.2.3-70-g09d2 From 641a82a1caa3d1b6bce9b7f12948566c272d0c12 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 26 Jan 2020 10:39:14 -0600 Subject: it turns out that there is no such thing as \n in html --- render.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/render.js b/render.js index 4e16168..583c09e 100644 --- a/render.js +++ b/render.js @@ -93,7 +93,9 @@ function render (msg, keys, preview) { var renderer = new marked.Renderer(); renderer.paragraph = function (paragraph) { + console.log(paragraph) var array = paragraph.split(' ') + console.log(array) for (i = 0; i < array.length; i++) { word = array[i] @@ -113,8 +115,9 @@ function render (msg, keys, preview) { } } - paragraph = array.join(' ') - return paragraph + newgraph = array.join(' ') + + return newgraph + '

' } renderer.link = function (href, title, text) { if ((href[0] == '@') || (href[0] == '%')) { -- cgit v1.2.3-70-g09d2 From d9325369c27eb5d96522d045004f32f1b01049f8 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 31 Jan 2020 16:10:45 -0600 Subject: fix bug where "end" variable was not cleared properly between hashtags --- render.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/render.js b/render.js index 583c09e..8033364 100644 --- a/render.js +++ b/render.js @@ -100,10 +100,11 @@ function render (msg, keys, preview) { for (i = 0; i < array.length; i++) { word = array[i] if (word.startsWith('#')) { + let end //console.log(word + ' is a hashtag') if ((word[word.length -1] === '.') || word[word.length - 1] === ',') { //console.log('and it ends with a ' + word[word.length - 1]) - var end = word[word.length - 1] + end = word[word.length - 1] word = word.substring(0, word.length - 1) } var hashtag = "" + word + "" -- cgit v1.2.3-70-g09d2