git ssb

0+

ev / gitmx



Tree: ae35d4b398efe8352b6b31fd5853d40aa9009cfc

Files: ae35d4b398efe8352b6b31fd5853d40aa9009cfc / avatar.js

2212 bytesRaw
1var pull = require('pull-stream')
2var query = require('./scuttlebot').query
3var h = require('hyperscript')
4var 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 = visualize(new Buffer(key.substring(1), 'base64'), 256)
38
39 if (ref.isFeedId(key)) {
40 avatar(sbot, id, key, function (err, data) {
41 if (err) throw err
42 if (data.image) {
43 localStorage[key + 'image'] = data.image
44 img.src = config.blobsUrl + data.image
45 }
46 })
47 }
48 return img
49}
50
51module.exports.cachedName = function (key) {
52 var avatarname = h('span', key.substring(0, 10))
53
54 if (localStorage[key + 'name']) {
55 avatarname.textContent = localStorage[key + 'name']
56 } else {
57 if (ref.isFeedId(key)) {
58 avatar(sbot, id, key, function (err, data) {
59 if (data.name) {
60 if (data.name[0] != '@') {
61 var name = '@' + data.name
62 } else {
63 var name = data.name
64 }
65 localStorage[key + 'name'] = name
66 avatarname.textContent = name
67 }
68 })
69 }
70 }
71
72 return avatarname
73}
74
75module.exports.cachedImage = function (key) {
76 var img = visualize(new Buffer(key.substring(1), 'base64'), 256)
77
78 if (localStorage[key + 'image']) {
79 img.src = config.blobsUrl + localStorage[key + 'image']
80 } else {
81 if (ref.isFeedId(key)) {
82 avatar(sbot, id, key, function (err, data) {
83 if (data.image) {
84 localStorage[key + 'image'] = data.image
85 img.src = config.blobsUrl + data.image
86 }
87 })
88 }
89 }
90
91 return img
92}
93

Built with git-ssb-web