Files: 1d4c84a26e992a18358cb0e3c675e1608c9f9ed7 / avatar.js
1187 bytesRaw
1 | var pull = require('pull-stream') |
2 | var query = require('./scuttlebot').query |
3 | var h = require('hyperscript') |
4 | var visualize = require('visualize-buffer') |
5 | |
6 | var sbot = require('./scuttlebot') |
7 | |
8 | var config = require('./config')() |
9 | |
10 | module.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 | |
32 | var ref = require('ssb-ref') |
33 | |
34 | module.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