aboutsummaryrefslogtreecommitdiff
path: root/lib/app.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-12-12 17:03:17 -0800
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-12-12 17:03:17 -0800
commitc329eae0e6ff3d36d7f21349980d51d9dd587faa (patch)
treeca9d4bea107b457cf5264ae9080cd8b533dec235 /lib/app.js
parenta34dfa54a947eb69c31b3196a8be8a8705a9f4b3 (diff)
downloadpatchfoo-c329eae0e6ff3d36d7f21349980d51d9dd587faa.tar.gz
patchfoo-c329eae0e6ff3d36d7f21349980d51d9dd587faa.zip
Calculate follows using ssb-contact
Avoid use of `live: true` which triggers a bug in the query engine. Use a single live stream to keep called-back objects up-to-date
Diffstat (limited to 'lib/app.js')
-rw-r--r--lib/app.js36
1 files changed, 4 insertions, 32 deletions
diff --git a/lib/app.js b/lib/app.js
index 643b317..fc395a2 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -8,6 +8,7 @@ var multicb = require('multicb')
var paramap = require('pull-paramap')
var Contacts = require('ssb-contact')
var About = require('./about')
+var Follows = require('./follows')
var Serve = require('./serve')
var Render = require('./render')
var Git = require('./git')
@@ -49,7 +50,6 @@ function App(sbot, config) {
this.reverseEmojiNameCache = lru(500)
this.getBlobSize = memo({cache: this.blobSizeCache = lru(100)},
sbot.blobs.size.bind(sbot.blobs))
- this.getFollows = memo(this._getFollows.bind(this))
this.getVotes = memo({cache: lru(100)}, this._getVotes.bind(this))
this.unboxMsg = this.unboxMsg.bind(this)
@@ -57,6 +57,7 @@ function App(sbot, config) {
this.render = new Render(this, this.opts)
this.git = new Git(this)
this.contacts = new Contacts(this.sbot)
+ this.follows = new Follows(this.sbot, this.contacts)
this.monitorBlobWants()
}
@@ -690,7 +691,7 @@ App.prototype.filterMsg = function (msg, opts, cb) {
|| author === myId
|| author === opts.feed
|| msg.key === opts.msgId) return cb(null, show)
- self.getFollows(myId, function (err, follows) {
+ self.follows.getFollows(myId, function (err, follows) {
if (err) return cb(err)
if (follows[author]) return cb(null, show)
self.getVotes(msg.key, function (err, votes) {
@@ -707,41 +708,12 @@ App.prototype.filterMsg = function (msg, opts, cb) {
App.prototype.isFollowing = function (src, dest, cb) {
var self = this
- self.getFollows(src, function (err, follows) {
+ self.follows.getFollows(src, function (err, follows) {
if (err) return cb(err)
return cb(null, follows[dest])
})
}
-App.prototype._getFollows = function (id, cb) {
- var follows = {}
- function ready(err) {
- if (!cb) return
- var _cb = cb
- cb = null
- _cb(err, follows)
- }
- pull(
- this.sbot.links2.read({
- live: true,
- query: [
- {$filter: {
- source: id,
- rel: [{$prefix: 'contact'}]
- }},
- {$map: {
- following: ['rel', 1],
- feed: 'dest'
- }}
- ]
- }),
- pull.drain(function (link) {
- if (link.sync) return ready()
- follows[link.feed] = link.following
- }, ready)
- )
-}
-
App.prototype._getVotes = function (id, cb) {
var votes = {}
pull(