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