aboutsummaryrefslogtreecommitdiff
path: root/views.js
diff options
context:
space:
mode:
Diffstat (limited to 'views.js')
-rw-r--r--views.js109
1 files changed, 102 insertions, 7 deletions
diff --git a/views.js b/views.js
index 1c4dca3..c108cfb 100644
--- a/views.js
+++ b/views.js
@@ -1,15 +1,47 @@
function threadPage (src, keys) {
get(src).then(msg => {
- open(msg).then(post => {
- scroller.appendChild(render(post, keys))
- })
+ scroller.appendChild(render(msg, keys))
})
}
function profilePage (src, keys) {
var server = 'ws://localhost:8080/'
- sync(src, server, keys)
+ var profile = h('div', {classList: 'profile'})
+
+ scroller.appendChild(profile)
+
+ var input = h('input', {placeholder: 'New name'})
+
+ profile.appendChild(h('a', {href: '#' + src}, [getName(src)]))
+
+ profile.appendChild(h('div', [
+ input,
+ h('button', {
+ onclick: function () {
+ content = {
+ type: 'name',
+ named: src,
+ name: input.value
+ }
+
+ publish(content, keys).then(function () {location.reload()})
+ }
+ }, ['Identify'])
+ ]))
+
+ profile.appendChild(h('button', {
+ onclick: function () {
+ sync(src, server, keys)
+ }
+ }, ['Sync feed']))
+
+ profile.appendChild(h('button', {
+ onclick: function () {
+ localforage.removeItem(src).then(function () { location.reload() })
+ }
+ }, ['Delete feed']))
+
bog(src).then(log => {
if (log) {
@@ -23,12 +55,75 @@ function profilePage (src, keys) {
}
function publicPage (keys) {
+ var newlog = []
+
+ scroller.appendChild(h('button', {
+ onclick: function () {
+ var openedlog = []
+ localforage.iterate(function(value, key, i) {
+ if (key[0] == '@') {
+ newlog = newlog.concat(value)
+ }
+ console.log(newlog)
+ }).then(function () {
+ newlog.forEach(function (msg) {
+ var pubkey = nacl.util.decodeBase64(msg.author.substring(1))
+ var sig = nacl.util.decodeBase64(msg.signature)
+ var opened = JSON.parse(nacl.util.encodeUTF8(nacl.sign.open(sig, pubkey)))
+ opened.key = msg.key
+
+ openedlog.push(opened)
+ })
+ console.log(openedlog)
+ localforage.setItem('log', openedlog).then(function () {location.reload()})
+ })
+ }
+ }, ['Merge']))
+
+ scroller.appendChild(h('button', {
+ onclick: function () {
+ localforage.getItem('log').then(log => {
+ log.sort((a, b) => a.timestamp - b.timestamp)
+ console.log(log)
+ var reversed = log.reverse()
+ localforage.setItem('log', reversed).then(function () {location.reload()})
+ })
+ }
+ }, ['Sort']))
+
+ scroller.appendChild(h('button', {
+ onclick: function () {
+ var openedlog = []
+ localforage.iterate(function(value, key, i) {
+ if (key[0] == '@') {
+ newlog = newlog.concat(value)
+ }
+ console.log(newlog)
+ }).then(function () {
+ newlog.forEach(function (msg) {
+ var pubkey = nacl.util.decodeBase64(msg.author.substring(1))
+ var sig = nacl.util.decodeBase64(msg.signature)
+ var opened = JSON.parse(nacl.util.encodeUTF8(nacl.sign.open(sig, pubkey)))
+ opened.key = msg.key
+
+ openedlog.push(opened)
+ })
+ console.log(openedlog)
+
+ openedlog.sort((a, b) => a.timestamp - b.timestamp)
+
+ var reversed = openedlog.reverse()
+
+ localforage.setItem('log', reversed).then(function () {location.reload()})
+ })
+
+ }
+ }, ['Regenerate']))
+
scroller.appendChild(composer(keys))
bog().then(log => {
log.forEach(function (msg) {
- open(msg).then(post => {
- scroller.appendChild(render(post, keys))
- })
+ scroller.appendChild(render(msg, keys))
})
})
}