diff options
author | Ev Bogue <ev@evbogue.com> | 2019-11-23 14:00:31 -0600 |
---|---|---|
committer | Ev Bogue <ev@evbogue.com> | 2019-11-23 14:00:31 -0600 |
commit | 7a03c9794381baba8f8e61be6d8c919907dcf641 (patch) | |
tree | 983180194394692d9c7c472c5cffe22da967e49a | |
parent | 0eb66af71c4e1ad3bad82aabc560c69835f2c48c (diff) |
add a quickName function that only looks at cached name
-rw-r--r-- | bog.js | 13 | ||||
-rw-r--r-- | composer.js | 2 | ||||
-rw-r--r-- | render.js | 51 | ||||
-rw-r--r-- | views.js | 15 |
4 files changed, 47 insertions, 34 deletions
@@ -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...'}) } @@ -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)) @@ -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) { |