aboutsummaryrefslogtreecommitdiff
path: root/lib/app.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-12-10 10:45:59 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-12-10 10:45:59 -1000
commita28f9dbb28295200e56066ac3ae75bc97b74669b (patch)
treebc981f3f7e8c0d60a1559782b0f35aba6b1d9a98 /lib/app.js
parentdee0312beda7583df48e969e27efc4e1865edc71 (diff)
downloadpatchfoo-a28f9dbb28295200e56066ac3ae75bc97b74669b.tar.gz
patchfoo-a28f9dbb28295200e56066ac3ae75bc97b74669b.zip
Handle missing rpc methods
Diffstat (limited to 'lib/app.js')
-rw-r--r--lib/app.js35
1 files changed, 27 insertions, 8 deletions
diff --git a/lib/app.js b/lib/app.js
index 6689a0e..901dc17 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -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
})