git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Tree: 3501e60932b1802ea5dbccb4e7a6aa81021cd254

Files: 3501e60932b1802ea5dbccb4e7a6aa81021cd254 / avatar.js

1981 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
14module.exports.name = function (key) {
15
16 var avatarname = h('span', key.substring(0, 10))
17
18 avatar(sbot, id, key, function (err, data) {
19 if (err) throw err
20 if (data.name) {
21 if (data.name[0] != '@') {
22 var name = '@' + data.name
23 } else {
24 var name = data.name
25 }
26 localStorage[key + 'name'] = name
27 avatarname.textContent = name
28 }
29 })
30
31 return avatarname
32}
33
34module.exports.image = function (key) {
35 var img = visualize(new Buffer(key.substring(1), 'base64'), 256)
36
37 avatar(sbot, id, key, function (err, data) {
38 if (err) throw err
39 if (data.image) {
40 localStorage[key + 'image'] = data.image
41 img.src = config.blobsUrl + data.image
42 }
43 })
44
45 return img
46}
47
48module.exports.cachedName = function (key) {
49 var avatarname = h('span', key.substring(0, 10))
50
51 if (localStorage[key + 'name']) {
52 avatarname.textContent = localStorage[key + 'name']
53 } else {
54 avatar(sbot, id, key, function (err, data) {
55 if (data.name) {
56 if (data.name[0] != '@') {
57 var name = '@' + data.name
58 } else {
59 var name = data.name
60 }
61 localStorage[key + 'name'] = name
62 avatarname.textContent = name
63 }
64 })
65 }
66
67 return avatarname
68}
69
70module.exports.cachedImage = function (key) {
71 var img = visualize(new Buffer(key.substring(1), 'base64'), 256)
72
73 if (localStorage[key + 'image']) {
74 img.src = config.blobsUrl + localStorage[key + 'image']
75 } else {
76 avatar(sbot, id, key, function (err, data) {
77 if (data.image) {
78 localStorage[key + 'image'] = data.image
79 img.src = config.blobsUrl + data.image
80 }
81 })
82 }
83
84 return img
85}
86

Built with git-ssb-web