Commit 33e3d7cfd2ea4ebdc8336656309afe5c2be5d035
refactor to use ssb-avatar, and remove a few plugins
Ev Bogue committed on 6/23/2018, 4:42:35 PMParent: 63cf354f441e6b8e90c022967862df01432d5ad6
Files changed
avatar.js | changed |
bin.js | changed |
index.js | changed |
package-lock.json | changed |
package.json | changed |
scuttlebot.js | changed |
tools.js | changed |
views.js | changed |
avatar.js | ||
---|---|---|
@@ -2,54 +2,82 @@ | ||
2 | 2 … | var query = require('./scuttlebot').query |
3 | 3 … | var h = require('hyperscript') |
4 | 4 … | var visualize = require('visualize-buffer') |
5 | 5 … | |
6 … | +var avatar = require('ssb-avatar') | |
7 … | + | |
6 | 8 … | var sbot = require('./scuttlebot') |
7 | 9 … | |
8 | 10 … | var config = require('./config')() |
9 | 11 … | |
10 | -module.exports.name = function (id) { | |
12 … | +var id = require('./keys').id | |
13 … | + | |
14 … | +module.exports.name = function (key) { | |
11 | 15 … | |
12 | - function getName (id) { | |
13 | - sbot.names.getSignifier(id, function (err, name) { | |
14 | - if (name) { | |
15 | - localStorage[id + 'name'] = '@' + name | |
16 | - avatarname.textContent = '@' + name | |
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 | |
17 | 24 … | } |
18 | - }) | |
19 | - } | |
20 | - | |
21 | - var avatarname = h('span', id.substring(0, 10)) | |
25 … | + localStorage[key + 'name'] = name | |
26 … | + avatarname.textContent = name | |
27 … | + } | |
28 … | + }) | |
22 | 29 … | |
23 | - if (localStorage[id + 'name']) { | |
24 | - name.textContent = localStorage[id + 'name'] | |
25 | - getName(id) | |
26 | - } else { | |
27 | - getName(id) | |
28 | - } | |
29 | 30 … | return avatarname |
30 | 31 … | } |
31 | 32 … | |
32 | -var ref = require('ssb-ref') | |
33 … | +module.exports.image = function (key) { | |
34 … | + var img = visualize(new Buffer(key.substring(1), 'base64'), 256) | |
33 | 35 … | |
34 | -module.exports.image = function (id) { | |
35 | - var img = visualize(new Buffer(id.substring(1), 'base64'), 256) | |
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 … | + }) | |
36 | 42 … | |
37 | - function getImage (id) { | |
38 | - sbot.names.getImageFor(id, function (err, image) { | |
39 | - if (image) { | |
40 | - localStorage[id + 'image'] = image | |
41 | - img.src = config.blobsUrl + image | |
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 | |
42 | 61 … | } |
43 | 62 … | }) |
44 | 63 … | } |
45 | 64 … | |
46 | - if (localStorage[id + 'image']) { | |
47 | - img.src = config.blobsUrl + localStorage[id + 'image'] | |
48 | - getImage(id) | |
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'] | |
49 | 73 … | } else { |
50 | - getImage(id) | |
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 … | + }) | |
51 | 80 … | } |
52 | 81 … | |
53 | 82 … | return img |
54 | 83 … | } |
55 | - |
bin.js | ||
---|---|---|
@@ -33,12 +33,9 @@ | ||
33 | 33 … | .use(require('ssb-friends')) |
34 | 34 … | .use(require('ssb-blobs')) |
35 | 35 … | .use(require('ssb-query')) |
36 | 36 … | .use(require('ssb-links')) |
37 | - .use(require('ssb-backlinks')) | |
38 | 37 … | .use(require('ssb-ebt')) |
39 | - .use(require('ssb-names')) | |
40 | - //.use(require('ssb-ooo')) | |
41 | 38 … | .use(require('scuttlebot/plugins/invite')) |
42 | 39 … | .use(require('scuttlebot/plugins/local')) |
43 | 40 … | .use(require('decent-ws')) |
44 | 41 … | .use({ |
index.js | ||
---|---|---|
@@ -30,9 +30,8 @@ | ||
30 | 30 … | } |
31 | 31 … | } |
32 | 32 … | })), |
33 | 33 … | h('li', h('a', {href: '#' }, 'All')), |
34 | - h('li', h('a', {href: '#queue'}, 'Queue')), | |
35 | 34 … | h('li', h('a', {href: '#key' }, 'Key')), |
36 | 35 … | h('li.right', h('a', {href: '#about'}, '?')) |
37 | 36 … | ) |
38 | 37 … | ) |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 200875 bytes New file size: 199529 bytes |
package.json | ||
---|---|---|
@@ -36,9 +36,9 @@ | ||
36 | 36 … | "rc": "^1.2.7", |
37 | 37 … | "scuttlebot": "^11.3.0", |
38 | 38 … | "simple-mime": "^0.1.0", |
39 | 39 … | "split-buffer": "^1.0.0", |
40 | - "ssb-backlinks": "^0.7.1", | |
40 … | + "ssb-avatar": "^0.2.0", | |
41 | 41 … | "ssb-blobs": "^1.1.5", |
42 | 42 … | "ssb-client": "^4.5.7", |
43 | 43 … | "ssb-ebt": "^5.1.5", |
44 | 44 … | "ssb-feed": "^2.3.0", |
@@ -47,10 +47,8 @@ | ||
47 | 47 … | "ssb-keys": "^7.0.16", |
48 | 48 … | "ssb-links": "^3.0.3", |
49 | 49 … | "ssb-markdown": "^3.6.0", |
50 | 50 … | "ssb-mentions": "^0.5.0", |
51 | - "ssb-names": "^3.1.2", | |
52 | - "ssb-ooo": "^1.0.9", | |
53 | 51 … | "ssb-query": "git+https://git@github.com/evbogue/ssb-query.git", |
54 | 52 … | "ssb-ref": "^2.11.1", |
55 | 53 … | "visualize-buffer": "0.0.1", |
56 | 54 … | "yargs": "^11.0.0" |
scuttlebot.js | |||
---|---|---|---|
@@ -64,39 +64,8 @@ | |||
64 | 64 … | CACHE[e.key] = CACHE[e.key] || e.value | |
65 | 65 … | }) | |
66 | 66 … | ) | |
67 | 67 … | }), | |
68 | - backlinks: rec.source(function (query) { | ||
69 | - return sbot.backlinks.read(query) | ||
70 | - }), | ||
71 | - names: { | ||
72 | - get: rec.async(function (opts, cb) { | ||
73 | - sbot.names.get(opts, cb) | ||
74 | - }), | ||
75 | - getImages: rec.async(function (opts, cb) { | ||
76 | - sbot.names.getImages(opts, cb) | ||
77 | - }), | ||
78 | - getImageFor: rec.async(function (opts, cb) { | ||
79 | - return sbot.names.getImageFor(opts, cb) | ||
80 | - if(images[opts]) cb(null, images[opts]) | ||
81 | - else | ||
82 | - sbot.names.getImageFor(opts, function (err, v) { | ||
83 | - if(err) cb(err) | ||
84 | - else cb(null, images[opts]= v) | ||
85 | - }) | ||
86 | - }), | ||
87 | - getSignifier: rec.async(function (opts, cb) { | ||
88 | - sbot.names.getSignifier(opts, cb) | ||
89 | - }), | ||
90 | - getSignifies: rec.async(function (opts, cb) { | ||
91 | - sbot.names.getSignifies(opts, cb) | ||
92 | - }) | ||
93 | - }, | ||
94 | - friends: { | ||
95 | - get: rec.async(function (opts, cb) { | ||
96 | - sbot.friends.get(opts, cb) | ||
97 | - }) | ||
98 | - }, | ||
99 | 68 … | query: rec.source(function (query) { | |
100 | 69 … | return sbot.query.read(query) | |
101 | 70 … | }), | |
102 | 71 … | get: rec.async(function (key, cb) { |
tools.js | ||
---|---|---|
@@ -30,9 +30,9 @@ | ||
30 | 30 … | followingCount++ |
31 | 31 … | followingcount.textContent = followingCount |
32 | 32 … | var gotIt = document.getElementById('following:' + msg.value.content.contact.substring(0, 44)) |
33 | 33 … | if (gotIt == null) { |
34 | - following.appendChild(h('a#following:'+ msg.value.content.contact.substring(0, 44), {title: avatar.name(msg.value.content.contact).textContent, href: '#' + msg.value.content.contact}, h('span.avatar--small', avatar.image(msg.value.content.contact)))) | |
34 … | + following.appendChild(h('a#following:'+ msg.value.content.contact.substring(0, 44), {title: avatar.cachedName(msg.value.content.contact).textContent, href: '#' + msg.value.content.contact}, h('span.avatar--small', avatar.cachedImage(msg.value.content.contact)))) | |
35 | 35 … | } |
36 | 36 … | } |
37 | 37 … | if (msg.value.content.following == false) { |
38 | 38 … | followingcount = document.getElementById('followingcount') |
@@ -86,9 +86,9 @@ | ||
86 | 86 … | followerCount++ |
87 | 87 … | followcount.textContent = followerCount |
88 | 88 … | var gotIt = document.getElementById('followers:' + msg.value.author.substring(0, 44)) |
89 | 89 … | if (gotIt == null) { |
90 | - followers.appendChild(h('a#followers:'+ msg.value.author.substring(0, 44), {title: avatar.name(msg.value.author).textContent, href: '#' + msg.value.author}, h('span.avatar--small', avatar.image(msg.value.author)))) | |
90 … | + followers.appendChild(h('a#followers:'+ msg.value.author.substring(0, 44), {title: avatar.cachedName(msg.value.author).textContent, href: '#' + msg.value.author}, h('span.avatar--small', avatar.cachedImage(msg.value.author)))) | |
91 | 91 … | } |
92 | 92 … | } |
93 | 93 … | if (msg.value.content.following == false) { |
94 | 94 … | followcount = document.getElementById('followercount') |
@@ -335,10 +335,10 @@ | ||
335 | 335 … | |
336 | 336 … | mini.appendChild( |
337 | 337 … | h('span.avatar', |
338 | 338 … | h('a', {href: '#' + msg.value.author}, |
339 | - h('span.avatar--small', avatar.image(msg.value.author)), | |
340 | - avatar.name(msg.value.author) | |
339 … | + h('span.avatar--small', avatar.cachedImage(msg.value.author)), | |
340 … | + avatar.cachedName(msg.value.author) | |
341 | 341 … | ) |
342 | 342 … | ) |
343 | 343 … | ) |
344 | 344 … | var lock = h('span.right', h('img.emoji', {src: config.emojiUrl + 'lock.png'})) |
@@ -363,10 +363,10 @@ | ||
363 | 363 … | var header = h('div.header') |
364 | 364 … | |
365 | 365 … | header.appendChild(h('span.avatar', |
366 | 366 … | h('a', {href: '#' + msg.value.author}, |
367 | - h('span.avatar--small', avatar.image(msg.value.author)), | |
368 | - avatar.name(msg.value.author) | |
367 … | + h('span.avatar--small', avatar.cachedImage(msg.value.author)), | |
368 … | + avatar.cachedName(msg.value.author) | |
369 | 369 … | ) |
370 | 370 … | ) |
371 | 371 … | ) |
372 | 372 … |
views.js | ||
---|---|---|
@@ -29,9 +29,9 @@ | ||
29 | 29 … | |
30 | 30 … | screen.appendChild(hyperscroll(content)) |
31 | 31 … | } |
32 | 32 … | |
33 | -var mentionsStream = function () { | |
33 … | +/*var mentionsStream = function () { | |
34 | 34 … | var content = h('div.content') |
35 | 35 … | |
36 | 36 … | var screen = document.getElementById('screen') |
37 | 37 … | |
@@ -64,9 +64,9 @@ | ||
64 | 64 … | query: [{$filter: {dest: id}}] |
65 | 65 … | }), |
66 | 66 … | stream.top(content) |
67 | 67 … | ) |
68 | -} | |
68 … | +}*/ | |
69 | 69 … | |
70 | 70 … | var userStream = function (src) { |
71 | 71 … | var content = h('div.content') |
72 | 72 … | var screen = document.getElementById('screen') |
@@ -267,10 +267,10 @@ | ||
267 | 267 … | if (ref.isFeed(src)) { |
268 | 268 … | userStream(src) |
269 | 269 … | } else if (ref.isMsg(src)) { |
270 | 270 … | msgThread(src) |
271 | - } else if (src == 'queue') { | |
272 | - mentionsStream() | |
271 … | + //} else if (src == 'queue') { | |
272 … | + // mentionsStream() | |
273 | 273 … | } else if (src == 'about') { |
274 | 274 … | about() |
275 | 275 … | } else if (src == 'edit') { |
276 | 276 … | edit() |
@@ -278,31 +278,5 @@ | ||
278 | 278 … | keyPage() |
279 | 279 … | } else { |
280 | 280 … | everythingStream() |
281 | 281 … | } |
282 | - | |
283 | - sbot.friends.get({dest: id}, function (err, follows) { | |
284 | - var currentScreen = document.getElementById('screen') | |
285 | - if (follows === null) { | |
286 | - if (document.getElementById('inviter')) { return } | |
287 | - var invitebox = h('input', {placeholder: 'Invite Code Here'}) | |
288 | - var invite = h('div.message#inviter', | |
289 | - 'Hey, no one follows you. Either ', h('a', {href: '#key'}, 'import your key'), ' or get an invite from a pub:', | |
290 | - h('br'), | |
291 | - invitebox, | |
292 | - h('button', 'Accept', {onclick: function (invite) { | |
293 | - sbot.acceptInvite(invitebox.value, function (err, invited) { | |
294 | - if (err) throw err | |
295 | - console.log(invited) | |
296 | - location.hash = '#' + id | |
297 | - location.hash = '#' | |
298 | - }) | |
299 | - }}) | |
300 | - ) | |
301 | - if (currentScreen.firstChild.firstChild) { | |
302 | - currentScreen.firstChild.insertBefore(invite, currentScreen.firstChild.firstChild) | |
303 | - } else { | |
304 | - currentScreen.firstChild.appendChild(invite) | |
305 | - } | |
306 | - } | |
307 | - }) | |
308 | 282 … | } |
Built with git-ssb-web