git ssb

2+

ev / mvd



Tree: ef33ab337c848fb05b567cdab92bd9a21bedfab5

Files: ef33ab337c848fb05b567cdab92bd9a21bedfab5 / avatar.js

1187 bytesRaw
1var pull = require('pull-stream')
2var query = require('./scuttlebot').query
3var h = require('hyperscript')
4var visualize = require('visualize-buffer')
5
6var sbot = require('./scuttlebot')
7
8var config = require('./config')()
9
10module.exports.name = function (id) {
11
12 function getName (id) {
13 sbot.names.getSignifier(id, function (err, name) {
14 if (name) {
15 localStorage[id + 'name'] = '@' + name
16 avatarname.textContent = '@' + name
17 }
18 })
19 }
20
21 var avatarname = h('span', id.substring(0, 10))
22
23 if (localStorage[id + 'name']) {
24 name.textContent = localStorage[id + 'name']
25 getName(id)
26 } else {
27 getName(id)
28 }
29 return avatarname
30}
31
32var ref = require('ssb-ref')
33
34module.exports.image = function (id) {
35 var img = visualize(new Buffer(id.substring(1), 'base64'), 256)
36
37 function getImage (id) {
38 sbot.names.getImageFor(id, function (err, image) {
39 if (image) {
40 localStorage[id + 'image'] = image
41 img.src = config.blobsUrl + image
42 }
43 })
44 }
45
46 if (localStorage[id + 'image']) {
47 img.src = config.blobsUrl + localStorage[id + 'image']
48 getImage(id)
49 } else {
50 getImage(id)
51 }
52
53 return img
54}
55
56

Built with git-ssb-web