diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2018-12-10 10:45:59 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2018-12-10 10:45:59 -1000 |
commit | a28f9dbb28295200e56066ac3ae75bc97b74669b (patch) | |
tree | bc981f3f7e8c0d60a1559782b0f35aba6b1d9a98 | |
parent | dee0312beda7583df48e969e27efc4e1865edc71 (diff) | |
download | patchfoo-a28f9dbb28295200e56066ac3ae75bc97b74669b.tar.gz patchfoo-a28f9dbb28295200e56066ac3ae75bc97b74669b.zip |
Handle missing rpc methods
-rw-r--r-- | lib/app.js | 35 | ||||
-rw-r--r-- | lib/contacts.js | 1 | ||||
-rw-r--r-- | lib/follows.js | 3 | ||||
-rw-r--r-- | lib/render-msg.js | 3 | ||||
-rw-r--r-- | lib/render.js | 9 | ||||
-rw-r--r-- | lib/serve.js | 10 |
6 files changed, 42 insertions, 19 deletions
@@ -58,7 +58,10 @@ function App(sbot, config) { this.getMsgOoo = memo({cache: this.msgCache}, this.getMsgOoo) this.getAbout = memo({cache: this.aboutCache = lru(500)}, this._getAbout.bind(this)) - this.unboxContent = memo({cache: lru(100)}, function(value, cb){sbot.private.unbox(value, cb)}) + this.unboxContent = memo({cache: lru(100)}, function(value, cb){ + if (!sbot.private || !sbot.private.unbox) return cb(new Error('missing sbot.private.unbox')) + sbot.private.unbox(value, cb) + }) this.reverseNameCache = lru(500) this.reverseEmojiNameCache = lru(500) this.getBlobSize = memo({cache: this.blobSizeCache = lru(100)}, @@ -91,7 +94,8 @@ App.prototype.go = function () { } // invalidate cached About info when new About messages come in - pull( + if (!self.sbot.links) return console.error('missing sbot.links') + else pull( self.sbot.links({rel: 'about', old: false, values: true}), pull.drain(function (link) { self.aboutCache.remove(link.dest) @@ -171,7 +175,7 @@ App.prototype.advancedSearch = function (opts) { reverse: true, }) : opts.source ? - this.sbot.createUserStream({ + this.sbotCreateUserStream({ reverse: true, id: opts.source }) @@ -511,7 +515,7 @@ App.prototype.unboxMessages = function () { App.prototype.streamChannels = function (opts) { return pull( - this.sbot.messagesByType({type: 'channel', reverse: true}), + this.sbotMessagesByType({type: 'channel', reverse: true}), this.unboxMessages(), pull.filter(function (msg) { return msg.value.content.subscribed @@ -545,7 +549,7 @@ App.prototype.streamMyChannels = function (id, opts) { ) return pull( - this.sbot.createUserStream({id: id, reverse: true}), + this.sbotCreateUserStream({id: id, reverse: true}), this.unboxMessages(), pull.map(function (msg) { return msg.value.content @@ -561,7 +565,7 @@ App.prototype.streamMyChannels = function (id, opts) { App.prototype.streamTags = function () { return pull( - this.sbot.messagesByType({type: 'tag', reverse: true}), + this.sbotMessagesByType({type: 'tag', reverse: true}), this.unboxMessages(), pull.filter(function (msg) { return !msg.value.content.message @@ -589,7 +593,7 @@ App.prototype.getVoted = function (_opts, cb) { var numItems = 0 var firstTimestamp, lastTimestamp pull( - self.sbot.messagesByType(opts), + self.sbotMessagesByType(opts), self.unboxMessages(), pull.take(function () { return numItems < _opts.limit @@ -1106,6 +1110,21 @@ App.prototype.getLineComments = function (opts, cb) { ) } +App.prototype.sbotLinks = function (opts) { + if (!this.sbot.links) return pull.error(new Error('missing sbot.links')) + return this.sbot.links(opts) +} + +App.prototype.sbotCreateUserStream = function (opts) { + if (!this.sbot.createUserStream) return pull.error(new Error('missing sbot.createUserStream')) + return this.sbot.createUserStream(opts) +} + +App.prototype.sbotMessagesByType = function (opts) { + if (!this.sbot.messagesByType) return pull.error(new Error('missing sbot.messagesByType')) + return this.sbot.messagesByType(opts) +} + App.prototype.getThread = function (msg) { return cat([ pull.once(msg), @@ -1113,7 +1132,7 @@ App.prototype.getThread = function (msg) { query: [ {$filter: {dest: msg.key}} ] - }) : this.sbot.links({ + }) : this.sbotLinks({ dest: msg.key, values: true }) diff --git a/lib/contacts.js b/lib/contacts.js index e1d4a0a..39e8cee 100644 --- a/lib/contacts.js +++ b/lib/contacts.js @@ -10,6 +10,7 @@ function Contacts(sbot) { } Contacts.prototype._createContactStream = function (source, dest) { + if (!this.sbot.links) return pull.error(new Error('missing sbot.links')) return pull( this.sbot.links({ source: source, diff --git a/lib/follows.js b/lib/follows.js index b262520..e1febc7 100644 --- a/lib/follows.js +++ b/lib/follows.js @@ -12,7 +12,8 @@ function Follows(sbot, contacts) { var followsCache = lru(100) this.getFollows = memo({cache: followsCache}, this.getFollows) - pull( + if (!sbot.messagesByType) console.error('missing messagesByType') + else pull( sbot.messagesByType({type: 'contact', old: false}), pull.drain(function (msg) { var author = msg && msg.value && msg.value.author diff --git a/lib/render-msg.js b/lib/render-msg.js index d76f126..1093710 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -218,7 +218,8 @@ RenderMsg.prototype.recpsIds = function () { } RenderMsg.prototype.buttonsCommon = function () { - var chan = this.msg.value.content.channel + var c = this.msg.value.content + var chan = c && c.channel var recps = this.recpsIds() return [ chan ? h('input', {type: 'hidden', name: 'channel', value: chan}) : '', diff --git a/lib/render.js b/lib/render.js index aade2f2..7e8ffc9 100644 --- a/lib/render.js +++ b/lib/render.js @@ -271,9 +271,9 @@ Render.prototype.avatarImage = function (link, cb) { if (link.image) gotAbout(null, link) else self.app.getAbout(link.link, gotAbout) function gotAbout(err, about) { - if (err) return cb(err) - if (!about.image) img.src = self.toUrl('/static/fallback.png') - else img.src = self.imageUrl(about.image) + if (err) console.trace(err) + img.src = about && about.image ? self.imageUrl(about.image) + : self.toUrl('/static/fallback.png') cb() } return img @@ -310,7 +310,8 @@ Render.prototype.idLink = function (link, cb) { if (err) return cb(err) a.href = self.toUrl(link.link) var sigil = link.link && link.link[0] || '@' - a.childNodes[0].textContent = sigil + link.name + var name = link.name || String(link.link).substr(1, 8) + '…' + a.childNodes[0].textContent = sigil + name cb() }) return a diff --git a/lib/serve.js b/lib/serve.js index fc8aa7b..f975f4b 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -1109,7 +1109,7 @@ Serve.prototype.type = function (path) { } pull( - this.app.sbot.messagesByType(opts), + this.app.sbotMessagesByType(opts), this.renderThreadPaginated(opts, null, q), this.wrapMessages(), this.wrapType(type), @@ -1204,7 +1204,7 @@ Serve.prototype.streamThreadWithComposer = function (opts) { self.getMsgDecryptedMaybeOoo(id, function (err, rootMsg) { if (err && err.name === 'NotFoundError') err = null, rootMsg = { key: id, value: {content: false}} - if (err) return cb(new Error(err.stack)) + if (err) return cb(new Error(err.stack || err)) if (!rootMsg) { console.log('id', id, 'opts', opts) } @@ -1224,7 +1224,7 @@ Serve.prototype.streamThreadWithComposer = function (opts) { self.app.unboxMessages(), pull.through(function (msg) { var c = msg && msg.value.content - if (!channel && c.channel) channel = c.channel + if (!channel && c && c.channel) channel = c.channel }), pull.collect(function (err, links) { if (err) return gotLinks(err) @@ -1290,11 +1290,11 @@ Serve.prototype.userFeed = function (id, path) { self.app.getAbout(id, function (err, about) { if (err) self.app.error(err) pull( - self.app.sbot.createUserStream(opts), + self.app.sbotCreateUserStream(opts), self.renderThreadPaginated(opts, id, q), self.wrapMessages(), self.wrapUserFeed(isScrolled, id), - self.wrapPage(about.name || id), + self.wrapPage(about && about.name || id), self.respondSink(200) ) }) |