git ssb

2+

ev / mvd



Commit 53dbb5aca4f28acaeb5e6ca9772c4640a81395ec

use ssb-friends and ssb-names for friends/avatars

Ev Bogue committed on 6/15/2018, 11:51:45 PM
Parent: eeeffa6970ed465663b4d879e6b0a672b8ad857c

Files changed

avatar.jschanged
bin.jschanged
manifest.jsonchanged
package-lock.jsonchanged
package.jsonchanged
render.jschanged
scuttlebot.jschanged
tools.jschanged
avatar.jsView
@@ -2,63 +2,54 @@
22 var query = require('./scuttlebot').query
33 var h = require('hyperscript')
44 var visualize = require('visualize-buffer')
55
6 +var sbot = require('./scuttlebot')
7 +
68 var config = require('./config')()
79
810 module.exports.name = function (id) {
911
1012 function getName (id) {
11- pull(query({query: [{$filter: { value: { author: id, content: {type: 'about', about: id, name: {'$truthy': true}}}}}], reverse: true}),
12- pull.collect(function (err, data){
13- if(data[0]) {
14- localStorage[id + 'name'] = '@' + data[0].value.content.name
15- name.textContent = localStorage[id + 'name']
13 + sbot.names.getSignifier(id, function (err, name) {
14 + if (name) {
15 + localStorage[id + 'name'] = '@' + name
16 + avatarname.textContent = '@' + name
1617 }
17- }))
18 + })
1819 }
1920
20- var name = h('span', id.substring(0, 10))
21 + var avatarname = h('span', id.substring(0, 10))
2122
2223 if (localStorage[id + 'name']) {
2324 name.textContent = localStorage[id + 'name']
2425 getName(id)
25- }
26- else {
26 + } else {
2727 getName(id)
2828 }
29-
30- return name
29 + return avatarname
3130 }
3231
3332 var ref = require('ssb-ref')
3433
3534 module.exports.image = function (id) {
35 + var img = visualize(new Buffer(id.substring(1), 'base64'), 256)
36 +
3637 function getImage (id) {
37- pull(query({query: [{$filter: { value: { author: id, content: {type: 'about', about: id, image: {'$truthy': true}}}}}], reverse: true}),
38- pull.collect(function (err, data){
39- if(data[0]) {
40- if (ref.isBlob(data[0].value.content.image.link)) {
41- var data = config.blobsUrl + data[0].value.content.image.link
42- localStorage[id + 'image'] = data
43- img.src = data
44- } else if (ref.isBlob(data[0].value.content.image)) {
45- var data = config.blobsUrl + data[0].value.content.image
46- localStorage[id + 'image'] = data
47- img.src = data
48- }
49- }
50- })
51- )
52- }
38 + sbot.names.getImageFor(id, function (err, image) {
39 + if (image) {
40 + localStorage[id + 'image'] = image
41 + img.src = config.blobsUrl + image
42 + }
43 + })
44 + }
5345
54- var img = visualize(new Buffer(id.substring(1), 'base64'), 256)
55-
5646 if (localStorage[id + 'image']) {
57- img.src = localStorage[id + 'image']
47 + img.src = config.blobsUrl + localStorage[id + 'image']
5848 getImage(id)
5949 } else {
6050 getImage(id)
6151 }
52 +
6253 return img
6354 }
6455
bin.jsView
@@ -35,9 +35,10 @@
3535 .use(require('ssb-query'))
3636 .use(require('ssb-links'))
3737 .use(require('ssb-backlinks'))
3838 .use(require('ssb-ebt'))
39- .use(require('ssb-ooo'))
39 + .use(require('ssb-names'))
40 + //.use(require('ssb-ooo'))
4041 .use(require('scuttlebot/plugins/invite'))
4142 .use(require('scuttlebot/plugins/local'))
4243 .use(require('decent-ws'))
4344 .use({
manifest.jsonView
@@ -42,8 +42,16 @@
4242 },
4343 "block": {
4444 "isBlocked": "sync"
4545 },
46 + "names": {
47 + "get": "async",
48 + "getImages": "async",
49 + "getImageFor": "async",
50 + "getSignifier": "async",
51 + "getSignifies": "async",
52 + "dump": "sync"
53 + },
4654 "private": {
4755 "publish": "async",
4856 "unbox": "sync"
4957 },
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 200019 bytes
New file size: 200424 bytes
package.jsonView
@@ -18,8 +18,9 @@
1818 "license": "MIT",
1919 "dependencies": {
2020 "decent-ws": "^1.0.1",
2121 "deep-extend": "^0.5.1",
22 + "emoji-server": "^1.0.0",
2223 "human-time": "0.0.1",
2324 "hyperloadmore": "^1.1.0",
2425 "hyperscript": "^2.0.2",
2526 "hyperscroll": "^1.0.0",
@@ -46,8 +47,9 @@
4647 "ssb-keys": "^7.0.16",
4748 "ssb-links": "^3.0.3",
4849 "ssb-markdown": "^3.6.0",
4950 "ssb-mentions": "^0.5.0",
51 + "ssb-names": "^3.1.2",
5052 "ssb-ooo": "^1.0.9",
5153 "ssb-query": "git+https://git@github.com/evbogue/ssb-query.git",
5254 "ssb-ref": "^2.11.1",
5355 "visualize-buffer": "0.0.1",
render.jsView
@@ -30,9 +30,8 @@
3030 message.appendChild(tools.mini(msg, privateMsg))
3131 return message
3232 }*/
3333 else if (msg.value.content.type == 'contact') {
34- console.log(msg)
3534 if (msg.value.content.following == true) {
3635 var following = h('span', ' follows ', h('a', {href: '#' + msg.value.content.contact}, avatar.name(msg.value.content.contact)))
3736 message.appendChild(tools.mini(msg, following))
3837 }
scuttlebot.jsView
@@ -64,8 +64,36 @@
6464 }),
6565 backlinks: rec.source(function (query) {
6666 return sbot.backlinks.read(query)
6767 }),
68 + names: {
69 + get: rec.async(function (opts, cb) {
70 + sbot.names.get(opts, cb)
71 + }),
72 + getImages: rec.async(function (opts, cb) {
73 + sbot.names.getImages(opts, cb)
74 + }),
75 + getImageFor: rec.async(function (opts, cb) {
76 + return sbot.names.getImageFor(opts, cb)
77 + if(images[opts]) cb(null, images[opts])
78 + else
79 + sbot.names.getImageFor(opts, function (err, v) {
80 + if(err) cb(err)
81 + else cb(null, images[opts]= v)
82 + })
83 + }),
84 + getSignifier: rec.async(function (opts, cb) {
85 + sbot.names.getSignifier(opts, cb)
86 + }),
87 + getSignifies: rec.async(function (opts, cb) {
88 + sbot.names.getSignifies(opts, cb)
89 + })
90 + },
91 + friends: {
92 + get: rec.async(function (opts, cb) {
93 + sbot.friends.get(opts, cb)
94 + })
95 + },
6896 query: rec.source(function (query) {
6997 return sbot.query.read(query)
7098 }),
7199 get: rec.async(function (key, cb) {
tools.jsView
@@ -13,79 +13,45 @@
1313
1414 var id = require('./keys').id
1515
1616 module.exports.getFollowing = function (src) {
17- var followingCount = 0
17 + var count = 0
1818
19- var following = h('div.following', 'Following: ')
19 + var following = h('div.following')
2020
21- following.appendChild(h('span#followingcount', '0'))
21 + following.appendChild(h('span', 'Following: ' + count))
2222 following.appendChild(h('br'))
2323
24- pull(
25- sbot.query({query: [{$filter: { value: { author: src, content: {type: 'contact'}}}}], live: true}),
26- pull.drain(function (msg) {
27- if (msg.value) {
28- if (msg.value.content.following == true) {
29- followingcount = document.getElementById('followingcount')
30- followingCount++
31- followingcount.textContent = followingCount
32- var gotIt = document.getElementById('following:' + msg.value.content.contact.substring(0, 44))
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))))
35- }
36- }
37- if (msg.value.content.following == false) {
38- followingcount = document.getElementById('followingcount')
39- followingCount--
40- followingcount.textContent = followingCount
41- var gotIt = document.getElementById('following:' + msg.value.content.contact.substring(0, 44))
42- if (gotIt != null) {
43- gotIt.outerHTML = ''
44- }
45- }
46- }
47- })
48- )
24 + sbot.friends.get({source: src}, function (err, follows) {
25 + for (var i in follows) {
26 + //this needs to iterative over each object within follows and only print if TRUE
27 + following.appendChild(h('a', {title: avatar.name(i).textContent, href: '#' + i}, h('span.avatar--small', avatar.image(i))))
28 + count++
29 + following.firstChild.textContent = 'Following: ' + count
30 + }
31 + })
4932
5033 return following
5134
5235 }
5336
5437 module.exports.getFollowers = function (src) {
55- var followerCount = 0
38 + var count = 0
5639
57- var followers = h('div.followers', 'Followers: ')
40 + var followers = h('div.followers')
5841
59- followers.appendChild(h('span#followercount', '0'))
42 + followers.appendChild(h('span', 'Followers: ' + count))
6043 followers.appendChild(h('br'))
6144
62- pull(
63- sbot.query({query: [{$filter: { value: { content: {type: 'contact', contact: src}}}}], live: true}),
64- pull.drain(function (msg) {
65- if (msg.value) {
66- if (msg.value.content.following == true) {
67- followcount = document.getElementById('followercount')
68- followerCount++
69- followcount.textContent = followerCount
70- var gotIt = document.getElementById('followers:' + msg.value.author.substring(0, 44))
71- if (gotIt == null) {
72- 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))))
73- }
74- }
75- if (msg.value.content.following == false) {
76- followcount = document.getElementById('followercount')
77- followerCount--
78- followcount.textContent = followerCount
79- var gotIt = document.getElementById('followers:' + msg.value.author.substring(0, 44))
80- if (gotIt != null) {
81- gotIt.outerHTML = ''
82- }
83- }
84- }
85- })
86- )
45 + sbot.friends.get({dest: src}, function (err, follows) {
46 + for (var i in follows) {
47 + followers.appendChild(h('a', {title: avatar.name(i).textContent, href: '#' + i}, h('span.avatar--small', avatar.image(i))))
48 + count++
49 + followers.firstChild.textContent = 'Followers: ' + count
50 + }
51 + })
8752
53 +
8854 return followers
8955 }
9056
9157 module.exports.follow = function (src) {

Built with git-ssb-web