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