git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Tree: d080fab1040ee385ad9148b260bd4d4bc77f1cd4

Files: d080fab1040ee385ad9148b260bd4d4bc77f1cd4 / avatar.js

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

Built with git-ssb-web