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 /lib/contact.js | |
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
Diffstat (limited to 'lib/contact.js')
-rw-r--r-- | lib/contact.js | 91 |
1 files changed, 0 insertions, 91 deletions
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 - }) - }) -} |