git ssb

1+

gb / ssblist



Tree: 285367a3b350be6649ad98e8eaa32e96912ebc51

Files: 285367a3b350be6649ad98e8eaa32e96912ebc51 / avatar.js

2406 bytesRaw
1var pull = require('pull-stream')
2var query = require('./scuttlebot').query
3var h = require('hyperscript')
4//var visualize = require('visualize-buffer')
5
6var avatar = require('ssb-avatar')
7
8var sbot = require('./scuttlebot')
9
10var config = require('./config')()
11
12var id = require('./keys').id
13
14var ref = require('ssb-ref')
15
16module.exports.name = function (key) {
17
18 var avatarname = h('span', key.substring(0, 10))
19 if (ref.isFeedId(key)) {
20 avatar(sbot, id, key, function (err, data) {
21 if (err) throw err
22 if (data.name) {
23 if (data.name[0] != '@') {
24 var name = '@' + data.name
25 } else {
26 var name = data.name
27 }
28 localStorage[key + 'name'] = name
29 avatarname.textContent = name
30 }
31 })
32 }
33 return avatarname
34}
35
36module.exports.image = function (key) {
37 var img = h('img',{src:'/blobs/get/&nI3ntGgvZrNsxc+20uzOIMGyF5w0AvIsOc2kcPcCz/s=.sha256'})
38 //var img = visualize(new Buffer(key.substring(1), 'base64'), 256)
39
40 if (ref.isFeedId(key)) {
41 avatar(sbot, id, key, function (err, data) {
42 if (err) throw err
43 if (data.image) {
44 localStorage[key + 'image'] = data.image
45 img.src = config.blobsUrl + data.image
46 }
47 })
48 }
49 return img
50}
51
52module.exports.cachedName = function (key) {
53 var avatarname = h('span', key.substring(0, 10))
54
55 if (localStorage[key + 'name']) {
56 avatarname.textContent = localStorage[key + 'name']
57 } else {
58 if (ref.isFeedId(key)) {
59 avatar(sbot, id, key, function (err, data) {
60 if (data.name) {
61 if (data.name[0] != '@') {
62 var name = '@' + data.name
63 } else {
64 var name = data.name
65 }
66 localStorage[key + 'name'] = name
67 avatarname.textContent = name
68 }
69 })
70 }
71 }
72
73 return avatarname
74}
75
76module.exports.cachedImage = function (key) {
77 var img = h('img',{src:'/blobs/get/&nI3ntGgvZrNsxc+20uzOIMGyF5w0AvIsOc2kcPcCz/s=.sha256'})
78 //var img = visualize(new Buffer(key.substring(1), 'base64'), 256)
79
80 if (localStorage[key + 'image']) {
81 img.src = config.blobsUrl + localStorage[key + 'image']
82 } else {
83 if (ref.isFeedId(key)) {
84 avatar(sbot, id, key, function (err, data) {
85 if (data.image) {
86 localStorage[key + 'image'] = data.image
87 img.src = config.blobsUrl + data.image
88 }
89 })
90 }
91 }
92
93 return img
94}
95

Built with git-ssb-web