git ssb

2+

ev / mvd



Commit 77f26b50550020fe2795e58ee7b816df90cdca45

make sure that key is a valid feedId before checking avatar

Ev Bogue committed on 6/25/2018, 11:39:52 PM
Parent: a91aacd99613bd8ba1f3551725dd523017b34d18

Files changed

avatar.jschanged
avatar.jsView
@@ -10,39 +10,42 @@
1010 var config = require('./config')()
1111
1212 var id = require('./keys').id
1313
14 +var ref = require('ssb-ref')
15 +
1416 module.exports.name = function (key) {
1517
1618 var avatarname = h('span', key.substring(0, 10))
17-
18- avatar(sbot, id, key, function (err, data) {
19- if (err) throw err
20- if (data.name) {
21- if (data.name[0] != '@') {
22- var name = '@' + data.name
23- } else {
24- var name = data.name
19 + if (ref.isFeedId(key)) {
20 + avatar(sbot, id, key, function (err, data) {
21 + if (err) throw err
22 + if (data.name) {
23 + if (data.name[0] != '@') {
24 + var name = '@' + data.name
25 + } else {
26 + var name = data.name
27 + }
28 + localStorage[key + 'name'] = name
29 + avatarname.textContent = name
2530 }
26- localStorage[key + 'name'] = name
27- avatarname.textContent = name
28- }
29- })
30-
31 + })
32 + }
3133 return avatarname
3234 }
3335
3436 module.exports.image = function (key) {
3537 var img = visualize(new Buffer(key.substring(1), 'base64'), 256)
3638
37- avatar(sbot, id, key, function (err, data) {
38- if (err) throw err
39- if (data.image) {
40- localStorage[key + 'image'] = data.image
41- img.src = config.blobsUrl + data.image
42- }
43- })
44-
39 + if (ref.isFeedId(key)) {
40 + avatar(sbot, id, key, function (err, data) {
41 + if (err) throw err
42 + if (data.image) {
43 + localStorage[key + 'image'] = data.image
44 + img.src = config.blobsUrl + data.image
45 + }
46 + })
47 + }
4548 return img
4649 }
4750
4851 module.exports.cachedName = function (key) {
@@ -50,19 +53,21 @@
5053
5154 if (localStorage[key + 'name']) {
5255 avatarname.textContent = localStorage[key + 'name']
5356 } else {
54- avatar(sbot, id, key, function (err, data) {
55- if (data.name) {
56- if (data.name[0] != '@') {
57- var name = '@' + data.name
58- } else {
59- var name = data.name
57 + if (ref.isFeedId(key)) {
58 + avatar(sbot, id, key, function (err, data) {
59 + if (data.name) {
60 + if (data.name[0] != '@') {
61 + var name = '@' + data.name
62 + } else {
63 + var name = data.name
64 + }
65 + localStorage[key + 'name'] = name
66 + avatarname.textContent = name
6067 }
61- localStorage[key + 'name'] = name
62- avatarname.textContent = name
63- }
64- })
68 + })
69 + }
6570 }
6671
6772 return avatarname
6873 }
@@ -72,14 +77,16 @@
7277
7378 if (localStorage[key + 'image']) {
7479 img.src = config.blobsUrl + localStorage[key + 'image']
7580 } else {
76- avatar(sbot, id, key, function (err, data) {
77- if (data.image) {
78- localStorage[key + 'image'] = data.image
79- img.src = config.blobsUrl + data.image
80- }
81- })
81 + if (ref.isFeedId(key)) {
82 + avatar(sbot, id, key, function (err, data) {
83 + if (data.image) {
84 + localStorage[key + 'image'] = data.image
85 + img.src = config.blobsUrl + data.image
86 + }
87 + })
88 + }
8289 }
8390
8491 return img
8592 }

Built with git-ssb-web