d27e69919c6e165cb97d628014fa2e1caf3577ba — Ev Bogue 3 months ago d9d0358
improvements to getname
4 files changed, 17 insertions(+), 11 deletions(-)

M app.js
M bog.js
M render.js
M views.js
M app.js => app.js +1 -1
@@ 26,7 26,7 @@ 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)])]),
+       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://github.com/bogbook/bog/'}, ['Git'])])

M bog.js => bog.js +9 -3
@@ 54,7 54,7 @@   // bog.getName -- iterates over a feed and returns a person's name
  
- function getName (id) {
+ function getName (id, keys) {
    var name = h('span')
  
    name.textContent = id.substring(0, 10) + '...'


@@ 62,10 62,16 @@ bog().then(log => {
      if (log) {
        for (var i = 0; i < log.length; i++ ) {
-         if (log[i].named == id) {
-           console.log(log[i].name)
+         if ((log[i].named === id) && (log[i].author === keys.publicKey)) {
+           // if you've identified someone as something else show that something else
+           console.log('I NAMED THEM ' + 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
+           console.log('THEY NAMED THEMSELVES ' + 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.
        }
      } 
    })

M render.js => render.js +6 -6
@@ 1,4 1,4 @@-function getHeader (post, mini) {
+ function getHeader (post, keys, mini) {
  
    var getRaw = h('button', {
      onclick: function () {


@@ 24,7 24,7 @@ ]),
      h('p', [
        h('a', {href: '#' + post.author}, [
-         getName(post.author)
+         getName(post.author, keys)
        ]),
        mini 
      ])


@@ 83,7 83,7 @@   
    if (msg.type == 'edit') {
-     message.appendChild(getHeader(msg))
+     message.appendChild(getHeader(msg, keys))
  
      message.appendChild(h('span', [
        'edited: ',


@@ 123,7 123,7 @@ }
  
    if (msg.type == 'post') {
-     message.appendChild(getHeader(msg))
+     message.appendChild(getHeader(msg, keys))
  
      if (msg.reply) {
        message.appendChild(h('span', [


@@ 131,7 131,7 @@ h('a', {href: '#' + msg.reply}, [msg.reply.substring(0, 10) + '...'])
        ]))
      }
-     var gotName = getName(msg.author)
+     var gotName = getName(msg.author, keys)
      message.appendChild(h('div',{id: 'content:' + msg.key, innerHTML: marked(msg.text)}))
      if (!preview) {
        message.appendChild(h('button', {


@@ 154,7 154,7 @@ }
      }
    } else if (msg.type == 'name') {
-     message.appendChild(getHeader(msg))
+     message.appendChild(getHeader(msg, keys))
  
      message.appendChild(h('span', ['identified ', h('a', {href: '#' + msg.named }, [msg.named.substring(0, 10) + '...']), ' as ' + msg.name]))
    } 

M views.js => views.js +1 -1
@@ 15,7 15,7 @@     var input = h('input', {placeholder: 'New name'})
  
-   profile.appendChild(h('a', {href: '#' + src}, [getName(src)]))
+   profile.appendChild(h('a', {href: '#' + src}, [getName(src, keys)]))
  
    profile.appendChild(h('div', [
      input,