Files: e6df6e1b2f7dfa90a55708989475b839f515ae28 / avatar.js
2212 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 | var ref = require('ssb-ref') |
15 | |
16 | module.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 | |
36 | module.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 | |
51 | module.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 | |
75 | module.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