Files: d080fab1040ee385ad9148b260bd4d4bc77f1cd4 / avatar.js
1935 bytesRaw
1 | var pull = require('pull-stream') |
2 | var query = require('./scuttlebot').query |
3 | var h = require('hyperscript') |
4 | var visualize = require('visualize-buffer') |
5 | |
6 | var avatar = require('ssb-avatar') |
7 | |
8 | var sbot = require('./scuttlebot') |
9 | |
10 | var config = require('./config')() |
11 | |
12 | var id = require('./keys').id |
13 | |
14 | module.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 | |
33 | module.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 | |
46 | module.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 | |
68 | module.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