git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Tree: 4d0fa57fa0b07dd3278b3f41e365de19466d62ee

Files: 4d0fa57fa0b07dd3278b3f41e365de19466d62ee / avatar.js

1616 bytesRaw
1var pull = require('pull-stream')
2var query = require('./scuttlebot').query
3var h = require('hyperscript')
4var visualize = require('visualize-buffer')
5
6var config = require('./config')()
7
8module.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
24var ref = require('ssb-ref')
25
26module.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