Files: 340be07ddda4e511bfce40504bcda7b43381ed1b / avatar.js
1981 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 (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 | |
34 | module.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 | |
48 | module.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 | |
70 | module.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