fix avatar cache to speed up image/name load time

master
Ev Bogue 4 years ago
parent 1833a4ad44
commit b7cbdc9c3c

@ -115,28 +115,20 @@ function getImage (id, keys, classList) {
var image = h('img', {classList: 'avatar'})
}
localforage.getItem('image:' + id).then(cache => {
//if (cache) {
// return image.src = cache
//} else {
bog().then(log => {
if (log) {
for (var i = 0; i < log.length; i++) {
if ((log[i].imaged === id) && (log[i].author === keys.publicKey)) {
// if you've identified someone as something else show that something else
localforage.setItem('image:' + id, log[i].image)
image.src = cache
return image.src = cache
} else if ((log[i].imaged === id) && (log[i].author === id)) {
// else if show the image they gave themselves
localforage.setItem('image:' + id, log[i].image)
image.src = cache
return image.src = cache
}
}
bog().then(log => {
if (log) {
for (var i = 0; i < log.length; i++) {
if ((log[i].imaged === id) && (log[i].author === keys.publicKey)) {
// if you've identified someone as something else show that something else
localforage.setItem('image:' + id, log[i].image)
return image.src = log[i].image
} else if ((log[i].imaged === id) && (log[i].author === id)) {
// else if show the image they gave themselves
localforage.setItem('image:' + id, log[i].image)
return image.src = log[i].image
}
})
//}
}
}
})
return image
}
@ -148,29 +140,46 @@ function getName (id, keys) {
name.textContent = id.substring(0, 10) + '...'
localforage.getItem('name:' + id).then(cache => {
bog().then(log => {
if (log) {
for (var i = 0; i < log.length; i++ ) {
if ((log[i].named === id) && (log[i].author === keys.publicKey)) {
// if you've identified someone as something else show that something else
localforage.setItem('name:' + id, 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
localforage.setItem('name:' + id, 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.
}
}
})
return name
}
function getQuickImage (id, keys) {
var image = h('img', {classList: 'avatar'})
localforage.getItem('image:' + id).then(cache => {
if (cache) {
//console.log(cache)
return name.textContent = '@' + cache
} else {
bog().then(log => {
if (log) {
for (var i = 0; i < log.length; i++ ) {
if ((log[i].named === id) && (log[i].author === keys.publicKey)) {
// if you've identified someone as something else show that something else
localforage.setItem('name:' + id, 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
localforage.setItem('name:' + id, 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.
}
}
})
image.src = cache
}
})
return image
}
function getQuickName (id, keys) {
var name = h('span', [id.substring(0, 10)])
localforage.getItem('name:' + id).then(cache => {
if (cache) {
name.textContent = '@' + cache
}
})
return name
}

@ -25,8 +25,8 @@ function getHeader (post, keys, mini) {
]),
h('p', [
h('a', {href: '#' + post.author}, [
getImage(post.author, keys),
getName(post.author, keys)
getQuickImage(post.author, keys),
getQuickName(post.author, keys)
]),
mini
])

Loading…
Cancel
Save