Commit 53dbb5aca4f28acaeb5e6ca9772c4640a81395ec
use ssb-friends and ssb-names for friends/avatars
Ev Bogue committed on 6/15/2018, 11:51:45 PMParent: eeeffa6970ed465663b4d879e6b0a672b8ad857c
Files changed
avatar.js | changed |
bin.js | changed |
manifest.json | changed |
package-lock.json | changed |
package.json | changed |
render.js | changed |
scuttlebot.js | changed |
tools.js | changed |
avatar.js | ||
---|---|---|
@@ -2,63 +2,54 @@ | ||
2 | 2 … | var query = require('./scuttlebot').query |
3 | 3 … | var h = require('hyperscript') |
4 | 4 … | var visualize = require('visualize-buffer') |
5 | 5 … | |
6 … | +var sbot = require('./scuttlebot') | |
7 … | + | |
6 | 8 … | var config = require('./config')() |
7 | 9 … | |
8 | 10 … | module.exports.name = function (id) { |
9 | 11 … | |
10 | 12 … | 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 | |
16 | 17 … | } |
17 | - })) | |
18 … | + }) | |
18 | 19 … | } |
19 | 20 … | |
20 | - var name = h('span', id.substring(0, 10)) | |
21 … | + var avatarname = h('span', id.substring(0, 10)) | |
21 | 22 … | |
22 | 23 … | if (localStorage[id + 'name']) { |
23 | 24 … | name.textContent = localStorage[id + 'name'] |
24 | 25 … | getName(id) |
25 | - } | |
26 | - else { | |
26 … | + } else { | |
27 | 27 … | getName(id) |
28 | 28 … | } |
29 | - | |
30 | - return name | |
29 … | + return avatarname | |
31 | 30 … | } |
32 | 31 … | |
33 | 32 … | var ref = require('ssb-ref') |
34 | 33 … | |
35 | 34 … | module.exports.image = function (id) { |
35 … | + var img = visualize(new Buffer(id.substring(1), 'base64'), 256) | |
36 … | + | |
36 | 37 … | 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 … | + } | |
53 | 45 … | |
54 | - var img = visualize(new Buffer(id.substring(1), 'base64'), 256) | |
55 | - | |
56 | 46 … | if (localStorage[id + 'image']) { |
57 | - img.src = localStorage[id + 'image'] | |
47 … | + img.src = config.blobsUrl + localStorage[id + 'image'] | |
58 | 48 … | getImage(id) |
59 | 49 … | } else { |
60 | 50 … | getImage(id) |
61 | 51 … | } |
52 … | + | |
62 | 53 … | return img |
63 | 54 … | } |
64 | 55 … |
bin.js | ||
---|---|---|
@@ -35,9 +35,10 @@ | ||
35 | 35 … | .use(require('ssb-query')) |
36 | 36 … | .use(require('ssb-links')) |
37 | 37 … | .use(require('ssb-backlinks')) |
38 | 38 … | .use(require('ssb-ebt')) |
39 | - .use(require('ssb-ooo')) | |
39 … | + .use(require('ssb-names')) | |
40 … | + //.use(require('ssb-ooo')) | |
40 | 41 … | .use(require('scuttlebot/plugins/invite')) |
41 | 42 … | .use(require('scuttlebot/plugins/local')) |
42 | 43 … | .use(require('decent-ws')) |
43 | 44 … | .use({ |
manifest.json | ||
---|---|---|
@@ -42,8 +42,16 @@ | ||
42 | 42 … | }, |
43 | 43 … | "block": { |
44 | 44 … | "isBlocked": "sync" |
45 | 45 … | }, |
46 … | + "names": { | |
47 … | + "get": "async", | |
48 … | + "getImages": "async", | |
49 … | + "getImageFor": "async", | |
50 … | + "getSignifier": "async", | |
51 … | + "getSignifies": "async", | |
52 … | + "dump": "sync" | |
53 … | + }, | |
46 | 54 … | "private": { |
47 | 55 … | "publish": "async", |
48 | 56 … | "unbox": "sync" |
49 | 57 … | }, |
package-lock.json | ||
---|---|---|
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.json | |||
---|---|---|---|
@@ -18,8 +18,9 @@ | |||
18 | 18 … | "license": "MIT", | |
19 | 19 … | "dependencies": { | |
20 | 20 … | "decent-ws": "^1.0.1", | |
21 | 21 … | "deep-extend": "^0.5.1", | |
22 … | + "emoji-server": "^1.0.0", | ||
22 | 23 … | "human-time": "0.0.1", | |
23 | 24 … | "hyperloadmore": "^1.1.0", | |
24 | 25 … | "hyperscript": "^2.0.2", | |
25 | 26 … | "hyperscroll": "^1.0.0", | |
@@ -46,8 +47,9 @@ | |||
46 | 47 … | "ssb-keys": "^7.0.16", | |
47 | 48 … | "ssb-links": "^3.0.3", | |
48 | 49 … | "ssb-markdown": "^3.6.0", | |
49 | 50 … | "ssb-mentions": "^0.5.0", | |
51 … | + "ssb-names": "^3.1.2", | ||
50 | 52 … | "ssb-ooo": "^1.0.9", | |
51 | 53 … | "ssb-query": "git+https://git@github.com/evbogue/ssb-query.git", | |
52 | 54 … | "ssb-ref": "^2.11.1", | |
53 | 55 … | "visualize-buffer": "0.0.1", |
render.js | ||
---|---|---|
@@ -30,9 +30,8 @@ | ||
30 | 30 … | message.appendChild(tools.mini(msg, privateMsg)) |
31 | 31 … | return message |
32 | 32 … | }*/ |
33 | 33 … | else if (msg.value.content.type == 'contact') { |
34 | - console.log(msg) | |
35 | 34 … | if (msg.value.content.following == true) { |
36 | 35 … | var following = h('span', ' follows ', h('a', {href: '#' + msg.value.content.contact}, avatar.name(msg.value.content.contact))) |
37 | 36 … | message.appendChild(tools.mini(msg, following)) |
38 | 37 … | } |
scuttlebot.js | ||
---|---|---|
@@ -64,8 +64,36 @@ | ||
64 | 64 … | }), |
65 | 65 … | backlinks: rec.source(function (query) { |
66 | 66 … | return sbot.backlinks.read(query) |
67 | 67 … | }), |
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 … | + }, | |
68 | 96 … | query: rec.source(function (query) { |
69 | 97 … | return sbot.query.read(query) |
70 | 98 … | }), |
71 | 99 … | get: rec.async(function (key, cb) { |
tools.js | ||
---|---|---|
@@ -13,79 +13,45 @@ | ||
13 | 13 … | |
14 | 14 … | var id = require('./keys').id |
15 | 15 … | |
16 | 16 … | module.exports.getFollowing = function (src) { |
17 | - var followingCount = 0 | |
17 … | + var count = 0 | |
18 | 18 … | |
19 | - var following = h('div.following', 'Following: ') | |
19 … | + var following = h('div.following') | |
20 | 20 … | |
21 | - following.appendChild(h('span#followingcount', '0')) | |
21 … | + following.appendChild(h('span', 'Following: ' + count)) | |
22 | 22 … | following.appendChild(h('br')) |
23 | 23 … | |
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 … | + }) | |
49 | 32 … | |
50 | 33 … | return following |
51 | 34 … | |
52 | 35 … | } |
53 | 36 … | |
54 | 37 … | module.exports.getFollowers = function (src) { |
55 | - var followerCount = 0 | |
38 … | + var count = 0 | |
56 | 39 … | |
57 | - var followers = h('div.followers', 'Followers: ') | |
40 … | + var followers = h('div.followers') | |
58 | 41 … | |
59 | - followers.appendChild(h('span#followercount', '0')) | |
42 … | + followers.appendChild(h('span', 'Followers: ' + count)) | |
60 | 43 … | followers.appendChild(h('br')) |
61 | 44 … | |
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 … | + }) | |
87 | 52 … | |
53 … | + | |
88 | 54 … | return followers |
89 | 55 … | } |
90 | 56 … | |
91 | 57 … | module.exports.follow = function (src) { |
Built with git-ssb-web