diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-11-25 20:07:18 -0700 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-11-25 20:13:41 -0700 |
commit | f51983b5e78e1dd23ae6482b97679a5618560429 (patch) | |
tree | b36fdcfb0bb4045b57427f186bab4a2a937d03df | |
parent | 59bfa01faf1939dc6b327b05439cb0b23cfddcfa (diff) | |
download | patchfoo-f51983b5e78e1dd23ae6482b97679a5618560429.tar.gz patchfoo-f51983b5e78e1dd23ae6482b97679a5618560429.zip |
Use ssb-contact again, with block(er)s
It streams the friends list rather than buffering it
-rw-r--r-- | lib/app.js | 7 | ||||
-rw-r--r-- | lib/contact.js | 91 | ||||
-rw-r--r-- | lib/serve.js | 59 | ||||
-rw-r--r-- | package-lock.json | 82 | ||||
-rw-r--r-- | package.json | 1 |
5 files changed, 80 insertions, 160 deletions
@@ -6,7 +6,7 @@ var u = require('./util') var pull = require('pull-stream') var multicb = require('multicb') var paramap = require('pull-paramap') -var getContacts = require('./contact') +var Contacts = require('ssb-contact') var About = require('./about') var Serve = require('./serve') var Render = require('./render') @@ -51,7 +51,6 @@ function App(sbot, config) { sbot.blobs.size.bind(sbot.blobs)) this.getFollows = memo(this._getFollows.bind(this)) this.getVotes = memo({cache: lru(100)}, this._getVotes.bind(this)) - this.getContacts = getContacts.bind(null, this.sbot) this.unboxMsg = this.unboxMsg.bind(this) @@ -465,6 +464,10 @@ App.prototype.streamMyChannels = function (id, opts) { ) } +App.prototype.createContactStreams = function (id) { + return new Contacts(this.sbot).createContactStreams(id) +} + function compareVoted(a, b) { return b.value - a.value } diff --git a/lib/contact.js b/lib/contact.js deleted file mode 100644 index c419921..0000000 --- a/lib/contact.js +++ /dev/null @@ -1,91 +0,0 @@ -var pull = require('pull-stream') -var multicb = require('multicb') - -function accumulateNonNull(a, b) { - return b == null ? a : b -} - -module.exports = function (sbot, id, cb) { - var followed = {}, followedBy = {}, blocked = {}, blockedBy = {} - var done = multicb({pluck: 1}) - pull( - sbot.links2.read({ - reverse: true, // oldest first. ssb-links has this switched - query: [ - {$filter: { - source: id, - rel: [{$prefix: 'contact'}] - }}, - {$reduce: { - id: 'dest', - following: {$collect: ['rel', 1]}, - blocking: {$collect: ['rel', 2]} - }} - ] - }), - pull.drain(function (op) { - var following = op.following.reduce(accumulateNonNull, null) - var blocking = op.blocking.reduce(accumulateNonNull, null) - if (following != null) followed[op.id] = following - if (blocking != null) blocked[op.id] = blocking - }, done()) - ) - pull( - sbot.links2.read({ - reverse: true, // oldest first. ssb-links has this switched - query: [ - {$filter: { - dest: id, - rel: [{$prefix: 'contact'}] - }}, - {$reduce: { - id: 'source', - following: {$collect: ['rel', 1]}, - blocking: {$collect: ['rel', 2]} - }} - ] - }), - pull.drain(function (op) { - var following = op.following.reduce(accumulateNonNull, null) - var blocking = op.blocking.reduce(accumulateNonNull, null) - if (following != null) followedBy[op.id] = following - if (blocking != null) blockedBy[op.id] = blocking - }, done()) - ) - - done(function (err) { - if (err) return cb(new Error(err.stack || err)) - var id - var friendsList = [] - var followingList = [] - var blockingList = [] - var followedByList = [] - var blockedByList = [] - - for (id in followed) { - if (followed[id]) { - if (followedBy[id]) friendsList.push(id) - else followingList.push(id) - } - } - for (id in followedBy) { - if (followedBy[id] && !followed[id]) { - followedByList.push(id) - } - } - for (id in blocked) { - if (blocked[id]) blockingList.push(id) - } - for (id in blockedBy) { - if (blockedBy[id]) blockedByList.push(id) - } - - cb(null, { - follows: followingList, - followers: followedByList, - friends: friendsList, - blocks: blockingList, - blockers: blockedByList - }) - }) -} diff --git a/lib/serve.js b/lib/serve.js index e05acd5..47bc7c2 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -797,10 +797,10 @@ Serve.prototype.channels = function (ext) { Serve.prototype.contacts = function (path) { var self = this var id = String(path).substr(1) + var contacts = self.app.createContactStreams(id) - function renderFriendsList(ids) { + function renderFriendsList() { return pull( - pull.values(ids), paramap(function (id, cb) { self.app.getAbout(id, function (err, about) { var name = about && about.name || id.substr(0, 8) + '…' @@ -815,40 +815,27 @@ Serve.prototype.contacts = function (path) { ) } - self.app.getContacts(id, function (err, contacts) { - if (err) return self.respond(500, err.stack || err) - pull( - cat([ - ph('section', {}, [ - ph('h3', {}, ['Contacts: ', self.phIdLink(id)]), - contacts.friends.length ? [ - ph('h4', {}, 'Friends'), - renderFriendsList(contacts.friends), - ] : [], - contacts.follows.length ? [ - ph('h4', {}, 'Follows'), - renderFriendsList(contacts.follows), - ] : [], - contacts.followers.length ? [ - ph('h4', {}, 'Followers'), - renderFriendsList(contacts.followers), - ] : [], - contacts.blocks.length ? [ - ph('h4', {}, 'Blocks'), - renderFriendsList(contacts.blocks), - ] : [], - contacts.blockers.length ? [ - ph('h4', {}, 'Blocked by'), - renderFriendsList(contacts.blockers), - ] : [], - ]) - ]), - self.wrapPage('contacts: ' + id), - self.respondSink(200, { - 'Content-Type': ctype('html') - }) - ) - }) + pull( + cat([ + ph('section', {}, [ + ph('h3', {}, ['Contacts: ', self.phIdLink(id)]), + ph('h4', {}, 'Friends'), + renderFriendsList()(contacts.friends), + ph('h4', {}, 'Follows'), + renderFriendsList()(contacts.follows), + ph('h4', {}, 'Followers'), + renderFriendsList()(contacts.followers), + ph('h4', {}, 'Blocks'), + renderFriendsList()(contacts.blocks), + ph('h4', {}, 'Blocked by'), + renderFriendsList()(contacts.blockers) + ]) + ]), + this.wrapPage('contacts: ' + id), + this.respondSink(200, { + 'Content-Type': ctype('html') + }) + ) } Serve.prototype.about = function (path) { diff --git a/package-lock.json b/package-lock.json index c5421b3..00a0bcb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -167,14 +167,14 @@ } }, "emoji-named-characters": { - "version": "1.0.2", - "resolved": "http://localhost:8989/blobs/get/&vW38X+lwPDgAzgY6z6k6r2l7BiROggivH7F4lIUga0U=.sha256" + "version": "http://localhost:8989/blobs/get/&vW38X+lwPDgAzgY6z6k6r2l7BiROggivH7F4lIUga0U=.sha256", + "integrity": "sha1-zes20OZgAsS5178d+8Ohmft9QJs=" }, "emoji-server": { - "version": "1.0.0", - "resolved": "http://localhost:8989/blobs/get/&Yt3cRdCu8ftMVwd+hBtgmrJ4ItRyrszK6Q5+qYTV8mw=.sha256", + "version": "http://localhost:8989/blobs/get/&Yt3cRdCu8ftMVwd+hBtgmrJ4ItRyrszK6Q5+qYTV8mw=.sha256", + "integrity": "sha1-0GPP7prxGMxa7vvC6bPdUIWBXGM=", "requires": { - "emoji-named-characters": "1.0.2" + "emoji-named-characters": "http://localhost:8989/blobs/get/&vW38X+lwPDgAzgY6z6k6r2l7BiROggivH7F4lIUga0U=.sha256" } }, "error-ex": { @@ -243,12 +243,12 @@ "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" }, "hashlru": { - "version": "2.2.0", - "resolved": "http://localhost:8989/blobs/get/&EASZ1/L+jHuTVxrgbQrNlTdCenA8etAVuk/TGn92RoY=.sha256" + "version": "http://localhost:8989/blobs/get/&EASZ1/L+jHuTVxrgbQrNlTdCenA8etAVuk/TGn92RoY=.sha256", + "integrity": "sha1-eTpYlD+QKupXgXfXsDNfE/JpS3E=" }, "highlight.js": { - "version": "9.12.0", - "resolved": "http://localhost:8989/blobs/get/&LK2T/oKc1S44QQjxG/3TDdR6OujGN7aWLR4It0ylTv4=.sha256" + "version": "http://localhost:8989/blobs/get/&LK2T/oKc1S44QQjxG/3TDdR6OujGN7aWLR4It0ylTv4=.sha256", + "integrity": "sha1-5tnb5Xy+/mB1HwKvM2GVhwyQwB4=" }, "hosted-git-info": { "version": "http://localhost:8989/blobs/get/&YUe3Q99bA5b/X94y+wiLwCspLENBKyIV4NuecamLnlE=.sha256", @@ -446,15 +446,15 @@ } }, "mime-types": { - "version": "2.1.17", - "resolved": "http://localhost:8989/blobs/get/&bZmlnBs3fRBs4JRo1O8ArQGuTHxuKwk+vj9dI3OdvLY=.sha256", + "version": "http://localhost:8989/blobs/get/&bZmlnBs3fRBs4JRo1O8ArQGuTHxuKwk+vj9dI3OdvLY=.sha256", + "integrity": "sha1-Cdejk/A+mVp5+K+Fe3Cp4KsWVXo=", "requires": { - "mime-db": "1.30.0" + "mime-db": "http://localhost:8989/blobs/get/&bthRei7RV8TfiQZxdmfGqc0N4W3c15dYuoEcDUFxyHY=.sha256" }, "dependencies": { "mime-db": { - "version": "1.30.0", - "resolved": "http://localhost:8989/blobs/get/&bthRei7RV8TfiQZxdmfGqc0N4W3c15dYuoEcDUFxyHY=.sha256" + "version": "http://localhost:8989/blobs/get/&bthRei7RV8TfiQZxdmfGqc0N4W3c15dYuoEcDUFxyHY=.sha256", + "integrity": "sha1-dMZD2i3Z1qRTmZY0ZbJtXKfXHwE=" } } }, @@ -698,9 +698,13 @@ "resolved": "http://localhost:8989/blobs/get/&+uVE8RHNwJIJa68sQGICGbxnCTCOdLLhSt/Pb4NmgL0=.sha256", "integrity": "sha256-+uVE8RHNwJIJa68sQGICGbxnCTCOdLLhSt/Pb4NmgL0=" }, + "pull-defer": { + "version": "0.2.2", + "resolved": "http://localhost:8989/blobs/get/&mDI2o/JC9yvFOVbeAhDN+hwTm7cK+dBwISYO49EMY24=.sha256" + }, "pull-git-packidx-parser": { - "version": "1.0.0", - "resolved": "http://localhost:8989/blobs/get/&ou0MPQZabBgzrHDu54jzLU3Sc6Rf5a/lost0whPQUJ0=.sha256", + "version": "http://localhost:8989/blobs/get/&ou0MPQZabBgzrHDu54jzLU3Sc6Rf5a/lost0whPQUJ0=.sha256", + "integrity": "sha1-LYvwr+SCSJfuA4QL/k9ahq/syiE=", "requires": { "pull-stream": "3.6.1" } @@ -737,29 +741,29 @@ "integrity": "sha256-mVOLtd5e8OPAoi/ARUMfEkgZlHrlkPzgapIlv2a9FwI=" }, "pull-hyperscript": { - "version": "0.2.2", - "resolved": "http://localhost:8989/blobs/get/&jMiBworh7lOvn5eH15aXOAVDHAJnsAVONJ3F6/+6lrg=.sha256", + "version": "http://localhost:8989/blobs/get/&jMiBworh7lOvn5eH15aXOAVDHAJnsAVONJ3F6/+6lrg=.sha256", + "integrity": "sha1-ykplgzYxhU9XWk4phVaMmQH1Y4M=", "requires": { "pull-cat": "1.1.11", "pull-stream": "3.6.1" } }, "pull-identify-filetype": { - "version": "1.1.0", - "resolved": "http://localhost:8989/blobs/get/&+bhhz+qZR+p9Q93DusCRsOAMc3mhNU7f11DnnB3FLFo=.sha256", + "version": "http://localhost:8989/blobs/get/&+bhhz+qZR+p9Q93DusCRsOAMc3mhNU7f11DnnB3FLFo=.sha256", + "integrity": "sha1-X5mvFeiEbUjs9iXtwkjsLPV/aw0=", "requires": { - "pull-stream": "2.28.4" + "pull-stream": "http://localhost:8989/blobs/get/&lilCQ+zOUuYxQdgWAG/nW1NGuFTlg0xJ0QhKwlJ7HWA=.sha256" }, "dependencies": { "pull-core": { - "version": "1.1.0", - "resolved": "http://localhost:8989/blobs/get/&HZk9i531Fe2BN93/439wkrzR5ItsqLTwkgOhYLs09ao=.sha256" + "version": "http://localhost:8989/blobs/get/&HZk9i531Fe2BN93/439wkrzR5ItsqLTwkgOhYLs09ao=.sha256", + "integrity": "sha1-PYEn1trBR1cFyYAJYfWdZsgEbIo=" }, "pull-stream": { - "version": "2.28.4", - "resolved": "http://localhost:8989/blobs/get/&lilCQ+zOUuYxQdgWAG/nW1NGuFTlg0xJ0QhKwlJ7HWA=.sha256", + "version": "http://localhost:8989/blobs/get/&lilCQ+zOUuYxQdgWAG/nW1NGuFTlg0xJ0QhKwlJ7HWA=.sha256", + "integrity": "sha1-fql0E8FhnCC8O9+eEOkTR7AyU+Q=", "requires": { - "pull-core": "1.1.0" + "pull-core": "http://localhost:8989/blobs/get/&HZk9i531Fe2BN93/439wkrzR5ItsqLTwkgOhYLs09ao=.sha256" } } } @@ -772,9 +776,16 @@ "multicb": "1.2.2" } }, + "pull-many": { + "version": "1.0.8", + "resolved": "http://localhost:8989/blobs/get/&wBHfPheBEjwjjkNoeM5mWtU/tYDs8+xnt5w6C1+EK3g=.sha256", + "requires": { + "pull-stream": "3.6.1" + } + }, "pull-paginate": { - "version": "1.0.0", - "resolved": "http://localhost:8989/blobs/get/&4gERPvcRCgSlKyybE+EiKHLIz4kbeSz5+T/MVAz0Jxo=.sha256" + "version": "http://localhost:8989/blobs/get/&4gERPvcRCgSlKyybE+EiKHLIz4kbeSz5+T/MVAz0Jxo=.sha256", + "integrity": "sha1-Y61Y76EGa8cBqlgamKPEHmrsf8I=" }, "pull-pair": { "version": "1.1.0", @@ -1042,6 +1053,15 @@ "rc": "1.2.1" } }, + "ssb-contact": { + "version": "1.1.0", + "resolved": "http://localhost:8989/blobs/get/&wU1gwlBbfFf8KL1Y+gBAYi7WapYmN2fg8ODKTpvfcbM=.sha256", + "requires": { + "pull-defer": "0.2.2", + "pull-many": "1.0.8", + "pull-stream": "3.6.1" + } + }, "ssb-keys": { "version": "7.0.10", "resolved": "http://localhost:8989/blobs/get/&/XLsWirGsUv3pQ11HIJwzZgLF7HVKQmd4QCt+nCDf6A=.sha256", @@ -1053,14 +1073,14 @@ } }, "ssb-marked": { - "version": "0.7.2", - "resolved": "http://localhost:8989/blobs/get/&5yyYBZpB4w+X6kW42KMh43Xz9KP3XW79mYOj40/CHA4=.sha256" + "version": "http://localhost:8989/blobs/get/&5yyYBZpB4w+X6kW42KMh43Xz9KP3XW79mYOj40/CHA4=.sha256", + "integrity": "sha1-Fg4kETeCqcpegGByqnpl58hl2/I=" }, "ssb-mentions": { "version": "http://localhost:8989/blobs/get/&GKwsJ3ykvOXc24wyNuWBdmnCFpQ+Ltd9ggjoOuOF/Pg=.sha256", "integrity": "sha1-en5LsSk2uHwNcjeC+b1ZMfuFef4=", "requires": { - "ssb-marked": "0.7.2", + "ssb-marked": "http://localhost:8989/blobs/get/&5yyYBZpB4w+X6kW42KMh43Xz9KP3XW79mYOj40/CHA4=.sha256", "ssb-ref": "http://localhost:8989/blobs/get/&wLimOD3785KVj7kBIAbjN6GH8EMhKRkcZSPrEMhdhks=.sha256" } }, diff --git a/package.json b/package.json index 53ae7e4..2dabe70 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "pull-reader": "^1.2.9", "pull-stream": "^3.5.0", "ssb-client": "http://localhost:8989/blobs/get/&EAaUpI+wrJM5/ly1RqZW0GAEF4PmCAmABBj7e6UIrL0=.sha256", + "ssb-contact": "^1.1.0", "ssb-marked": "^0.7.1", "ssb-mentions": "http://localhost:8989/blobs/get/&GKwsJ3ykvOXc24wyNuWBdmnCFpQ+Ltd9ggjoOuOF/Pg=.sha256", "ssb-sort": "^1.0.0", |