Files: 7a856ed68d3f4c64fac98fce38e8ead1b4b005e1 / avatar.js
1771 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 config = require('./config')() |
7 | |
8 | module.exports.name = function (id) { |
9 | |
10 | function getName (id) { |
11 | pull(query({query: [{$filter: { value: { author: id, content: {type: 'about', about: id, name: {'$truthy': true}}}}}], reverse: true}), |
12 | pull.collect(function (err, data){ |
13 | if(data[0]) { |
14 | localStorage[id + 'name'] = '@' + data[0].value.content.name |
15 | name.textContent = localStorage[id + 'name'] |
16 | } |
17 | })) |
18 | } |
19 | |
20 | var name = h('span', id.substring(0, 10)) |
21 | |
22 | if (localStorage[id + 'name']) { |
23 | name.textContent = localStorage[id + 'name'] |
24 | getName(id) |
25 | } |
26 | else { |
27 | getName(id) |
28 | } |
29 | |
30 | return name |
31 | } |
32 | |
33 | var ref = require('ssb-ref') |
34 | |
35 | module.exports.image = function (id) { |
36 | function getImage (id) { |
37 | pull(query({query: [{$filter: { value: { author: id, content: {type: 'about', about: id, image: {'$truthy': true}}}}}], reverse: true}), |
38 | pull.collect(function (err, data){ |
39 | if(data[0]) { |
40 | if (ref.isBlob(data[0].value.content.image.link)) { |
41 | var data = config.blobsUrl + data[0].value.content.image.link |
42 | localStorage[id + 'image'] = data |
43 | img.src = data |
44 | } else if (ref.isBlob(data[0].value.content.image)) { |
45 | var data = config.blobsUrl + data[0].value.content.image |
46 | localStorage[id + 'image'] = data |
47 | img.src = data |
48 | } |
49 | } |
50 | }) |
51 | ) |
52 | } |
53 | |
54 | var img = visualize(new Buffer(id.substring(1), 'base64'), 256) |
55 | |
56 | if (localStorage[id + 'image']) { |
57 | img.src = localStorage[id + 'image'] |
58 | getImage(id) |
59 | } else { |
60 | getImage(id) |
61 | } |
62 | return img |
63 | } |
64 | |
65 |
Built with git-ssb-web