aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEv Bogue <ev@evbogue.com>2019-12-22 13:27:05 -0600
committerEv Bogue <ev@evbogue.com>2019-12-22 13:27:05 -0600
commite8b76b2b33de8bbe053422d5e679a4d425e67b8e (patch)
tree3f08d2c355c4dd2f3e3a8d22e5b8e8bc631d6213
parentb9a1917fdbc5d79d58b4c7b9e268d555e97624ca (diff)
unboxable messages were removing beacon box
-rw-r--r--render.js108
1 files changed, 55 insertions, 53 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)
+ 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)
+ })
- var tobox = {
- author: keys.publicKey,
- timestamp: Date.now(),
- content: '>' + msg.content + '\n\nHeard.'
- }
+ } 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)
+ })
+ }
})
}