aboutsummaryrefslogtreecommitdiff
path: root/lib/app.js
diff options
context:
space:
mode:
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
})