aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-04-20 19:34:32 -0700
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-04-20 20:01:35 -0700
commit75fa67ce9869076f2d1994902b2a6a2c14807856 (patch)
tree8800b6fa7fd2e13ec28f079f2970438996a1f353
parente46be6be1dc1edb50867e971eced70a5a1e78295 (diff)
downloadpatchfoo-75fa67ce9869076f2d1994902b2a6a2c14807856.tar.gz
patchfoo-75fa67ce9869076f2d1994902b2a6a2c14807856.zip
Factor out contacts stream handling
-rw-r--r--lib/app.js114
-rw-r--r--package.json3
2 files changed, 3 insertions, 114 deletions
diff --git a/lib/app.js b/lib/app.js
index da15d28..b64ec2a 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -8,8 +8,7 @@ var ssbAvatar = require('ssb-avatar')
var hasher = require('pull-hash/ext/ssb')
var multicb = require('multicb')
var paramap = require('pull-paramap')
-var many = require('pull-many')
-var defer = require('pull-defer')
+var Contacts = require('ssb-contact')
var Serve = require('./serve')
var Render = require('./render')
@@ -243,115 +242,6 @@ App.prototype.streamChannels = function (opts) {
)
}
-App.prototype.streamFollows = function (id) {
- return pull(
- this.sbot.links({
- source: id,
- rel: 'contact',
- values: true,
- reverse: true,
- }),
- pull.map(function (msg) {
- return msg.value.content
- }),
- pull.filter(),
- pull.unique(function (c) {
- return c.contact
- }),
- pull.filter(function (c) {
- return c.following
- }),
- pull.map(function (c) {
- return c.contact
- })
- )
-}
-
-App.prototype.streamFollowers = function (id) {
- return pull(
- this.sbot.links({
- dest: id,
- rel: 'contact',
- values: true,
- reverse: true,
- }),
- pull.unique(function (msg) {
- return msg.value.author
- }),
- pull.filter(function (msg) {
- var c = msg.value.content
- return c && c.following
- }),
- pull.map(function (msg) {
- return msg.value.author
- })
- )
-}
-
-App.prototype.streamFriends = function (id, endCb) {
- var follows = {}, followers = {}
- return pull(
- many([
- pull(
- this.streamFollows(id),
- pull.map(function (id) {
- return {id: id, follow: true}
- })
- ),
- pull(
- this.streamFollowers(id),
- pull.map(function (id) {
- return {id: id, follower: true}
- })
- )
- ]),
- pull.filter(function (op) {
- if (op.follow) {
- if (followers[op.id]) {
- delete followers[op.id]
- return true
- } else {
- follows[op.id] = true
- return false
- }
- }
- if (op.follower) {
- if (follows[op.id]) {
- delete follows[op.id]
- return true
- } else {
- followers[op.id] = true
- return false
- }
- }
- }),
- pull.map(function (op) {
- return op.id
- }),
- endCb && function (read) {
- return function (abort, cb) {
- read(abort, function (end, data) {
- cb(end, data)
- if (end) endCb(end === true ? null : end, {
- followers: Object.keys(followers),
- follows: Object.keys(follows),
- })
- })
- }
- }
- )
-}
-
App.prototype.createContactStreams = function (id) {
- var follows = defer.source()
- var followers = defer.source()
- var friends = this.streamFriends(id, function (err, more) {
- follows.resolve(err ? pull.error(err) : pull.values(more.follows))
- followers.resolve(err ? pull.error(err) : pull.values(more.followers))
- })
- return {
- friends: friends,
- follows: follows,
- followers: followers,
- }
+ return new Contacts(this.sbot).createContactStreams(id)
}
diff --git a/package.json b/package.json
index 28f1704..1bc5812 100644
--- a/package.json
+++ b/package.json
@@ -13,15 +13,14 @@
"mime-types": "^2.1.12",
"multicb": "^1.2.1",
"pull-cat": "^1.1.11",
- "pull-defer": "^0.2.2",
"pull-hash": "^1.0.0",
"pull-hyperscript": "^0.2.2",
"pull-identify-filetype": "^1.1.0",
- "pull-many": "^1.0.8",
"pull-paginate": "^1.0.0",
"pull-paramap": "^1.2.1",
"pull-stream": "^3.5.0",
"ssb-avatar": "^0.2.0",
+ "ssb-contact": "^1.0.0",
"ssb-marked": "^0.7.1",
"ssb-mentions": "^0.2.0",
"ssb-party": "^0.3.0",