git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Commit 33e3d7cfd2ea4ebdc8336656309afe5c2be5d035

refactor to use ssb-avatar, and remove a few plugins

Ev Bogue committed on 6/23/2018, 4:42:35 PM
Parent: 63cf354f441e6b8e90c022967862df01432d5ad6

Files changed

avatar.jschanged
bin.jschanged
index.jschanged
package-lock.jsonchanged
package.jsonchanged
scuttlebot.jschanged
tools.jschanged
views.jschanged
avatar.jsView
@@ -2,54 +2,82 @@
22 var query = require('./scuttlebot').query
33 var h = require('hyperscript')
44 var visualize = require('visualize-buffer')
55
6+var avatar = require('ssb-avatar')
7+
68 var sbot = require('./scuttlebot')
79
810 var config = require('./config')()
911
10-module.exports.name = function (id) {
12+var id = require('./keys').id
13+
14+module.exports.name = function (key) {
1115
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
1724 }
18- })
19- }
20-
21- var avatarname = h('span', id.substring(0, 10))
25+ localStorage[key + 'name'] = name
26+ avatarname.textContent = name
27+ }
28+ })
2229
23- if (localStorage[id + 'name']) {
24- name.textContent = localStorage[id + 'name']
25- getName(id)
26- } else {
27- getName(id)
28- }
2930 return avatarname
3031 }
3132
32-var ref = require('ssb-ref')
33+module.exports.image = function (key) {
34+ var img = visualize(new Buffer(key.substring(1), 'base64'), 256)
3335
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+ })
3642
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
4261 }
4362 })
4463 }
4564
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']
4973 } 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+ })
5180 }
5281
5382 return img
5483 }
55-
bin.jsView
@@ -33,12 +33,9 @@
3333 .use(require('ssb-friends'))
3434 .use(require('ssb-blobs'))
3535 .use(require('ssb-query'))
3636 .use(require('ssb-links'))
37- .use(require('ssb-backlinks'))
3837 .use(require('ssb-ebt'))
39- .use(require('ssb-names'))
40- //.use(require('ssb-ooo'))
4138 .use(require('scuttlebot/plugins/invite'))
4239 .use(require('scuttlebot/plugins/local'))
4340 .use(require('decent-ws'))
4441 .use({
index.jsView
@@ -30,9 +30,8 @@
3030 }
3131 }
3232 })),
3333 h('li', h('a', {href: '#' }, 'All')),
34- h('li', h('a', {href: '#queue'}, 'Queue')),
3534 h('li', h('a', {href: '#key' }, 'Key')),
3635 h('li.right', h('a', {href: '#about'}, '?'))
3736 )
3837 )
package-lock.jsonView
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.jsonView
@@ -36,9 +36,9 @@
3636 "rc": "^1.2.7",
3737 "scuttlebot": "^11.3.0",
3838 "simple-mime": "^0.1.0",
3939 "split-buffer": "^1.0.0",
40- "ssb-backlinks": "^0.7.1",
40+ "ssb-avatar": "^0.2.0",
4141 "ssb-blobs": "^1.1.5",
4242 "ssb-client": "^4.5.7",
4343 "ssb-ebt": "^5.1.5",
4444 "ssb-feed": "^2.3.0",
@@ -47,10 +47,8 @@
4747 "ssb-keys": "^7.0.16",
4848 "ssb-links": "^3.0.3",
4949 "ssb-markdown": "^3.6.0",
5050 "ssb-mentions": "^0.5.0",
51- "ssb-names": "^3.1.2",
52- "ssb-ooo": "^1.0.9",
5351 "ssb-query": "git+https://git@github.com/evbogue/ssb-query.git",
5452 "ssb-ref": "^2.11.1",
5553 "visualize-buffer": "0.0.1",
5654 "yargs": "^11.0.0"
scuttlebot.jsView
@@ -64,39 +64,8 @@
6464 CACHE[e.key] = CACHE[e.key] || e.value
6565 })
6666 )
6767 }),
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- },
9968 query: rec.source(function (query) {
10069 return sbot.query.read(query)
10170 }),
10271 get: rec.async(function (key, cb) {
tools.jsView
@@ -30,9 +30,9 @@
3030 followingCount++
3131 followingcount.textContent = followingCount
3232 var gotIt = document.getElementById('following:' + msg.value.content.contact.substring(0, 44))
3333 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))))
3535 }
3636 }
3737 if (msg.value.content.following == false) {
3838 followingcount = document.getElementById('followingcount')
@@ -86,9 +86,9 @@
8686 followerCount++
8787 followcount.textContent = followerCount
8888 var gotIt = document.getElementById('followers:' + msg.value.author.substring(0, 44))
8989 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))))
9191 }
9292 }
9393 if (msg.value.content.following == false) {
9494 followcount = document.getElementById('followercount')
@@ -335,10 +335,10 @@
335335
336336 mini.appendChild(
337337 h('span.avatar',
338338 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)
341341 )
342342 )
343343 )
344344 var lock = h('span.right', h('img.emoji', {src: config.emojiUrl + 'lock.png'}))
@@ -363,10 +363,10 @@
363363 var header = h('div.header')
364364
365365 header.appendChild(h('span.avatar',
366366 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)
369369 )
370370 )
371371 )
372372
views.jsView
@@ -29,9 +29,9 @@
2929
3030 screen.appendChild(hyperscroll(content))
3131 }
3232
33-var mentionsStream = function () {
33+/*var mentionsStream = function () {
3434 var content = h('div.content')
3535
3636 var screen = document.getElementById('screen')
3737
@@ -64,9 +64,9 @@
6464 query: [{$filter: {dest: id}}]
6565 }),
6666 stream.top(content)
6767 )
68-}
68+}*/
6969
7070 var userStream = function (src) {
7171 var content = h('div.content')
7272 var screen = document.getElementById('screen')
@@ -267,10 +267,10 @@
267267 if (ref.isFeed(src)) {
268268 userStream(src)
269269 } else if (ref.isMsg(src)) {
270270 msgThread(src)
271- } else if (src == 'queue') {
272- mentionsStream()
271+ //} else if (src == 'queue') {
272+ // mentionsStream()
273273 } else if (src == 'about') {
274274 about()
275275 } else if (src == 'edit') {
276276 edit()
@@ -278,31 +278,5 @@
278278 keyPage()
279279 } else {
280280 everythingStream()
281281 }
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- })
308282 }

Built with git-ssb-web