aboutsummaryrefslogtreecommitdiff
path: root/lib/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/app.js')
-rw-r--r--lib/app.js45
1 files changed, 34 insertions, 11 deletions
diff --git a/lib/app.js b/lib/app.js
index 1ca864e..3847247 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -24,6 +24,7 @@ var path = require('path')
var fs = require('fs')
var mkdirp = require('mkdirp')
var Base64URL = require('base64-url')
+var ssbKeys = require('ssb-keys')
var zeros = new Buffer(24); zeros.fill(0)
@@ -69,10 +70,7 @@ 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){
- if (!sbot.private || !sbot.private.unbox) return cb(new Error('missing sbot.private.unbox'))
- sbot.private.unbox(value, cb)
- })
+ this.unboxContent = memo({cache: lru(100)}, this.unboxContent.bind(this))
this.reverseNameCache = lru(500)
this.reverseEmojiNameCache = lru(500)
this.getBlobSize = memo({cache: this.blobSizeCache = lru(100)},
@@ -96,7 +94,7 @@ function App(sbot, config) {
this.navLinks = conf.nav || [
'new',
'public',
- 'private',
+ this.sbot.private && 'private',
'mentions',
'peers',
this.sbot.status && 'status',
@@ -144,6 +142,22 @@ var logPrefix = '[' + pkg.name + ']'
App.prototype.log = console.log.bind(console, logPrefix)
App.prototype.error = console.error.bind(console, logPrefix)
+App.prototype.unboxContent = function (content, cb) {
+ if (this.sbot.private && this.sbot.private.unbox) return this.sbot.private.unbox(content, cb)
+ if (typeof content !== 'string') return cb(new TypeError('content must be string'))
+ // Missing ssb-private and privat key
+ var keys = this.config.keys || {}
+ if (!keys.private) {
+ // Missing ssb-private and private key, so cannot decrypt here.
+ // ssb-server may do decryption anyway, with private:true RPC option.
+ return cb(null, null)
+ }
+ var data
+ try { data = ssbKeys.unbox(content, this.config.keys.private) }
+ catch(e) { return cb(e) }
+ cb(null, data)
+}
+
App.prototype.unboxContentWithKey = function (content, key, cb) {
if (!key) return this.unboxContent(content, cb)
var data
@@ -205,6 +219,7 @@ App.prototype.advancedSearch = function (opts) {
dest: opts.dest,
source: opts.source || undefined,
reverse: true,
+ meta: false,
})
: opts.source ?
this.sbotCreateUserStream({
@@ -440,8 +455,12 @@ function sbotGet(sbot, id, cb) {
// ssb-ooo@1.0.1 (a50da3928500f3ac0fbead0a1b335a3dd5bbc096): raw=true
// ssb-ooo@1.1.0 (f7302d12e56d566b84205bbc0c8b882ae6fd9b12): ooo=false
if (sbot.ooo) {
- sbot.get({id: id, raw: true, ooo: false}, cb)
+ sbot.get({id: id, raw: true, ooo: false, private: true}, cb)
} else {
+ if (!sbot.private) {
+ // if no sbot.private, assume we have newer sbot that supports private:true
+ return sbot.get({id: id, private: true}, cb)
+ }
sbot.get(id, cb)
}
}
@@ -541,7 +560,7 @@ App.prototype.isMuted = function (id, cb) {
var self = this
pull(
self.sbot.links({source: self.sbot.id, dest: id, rel: 'contact', reverse: true,
- values: true}),
+ values: true, meta: false}), // meta:false to emulate private:true
pull.filter(function (msg) {
return msg && msg.value && typeof msg.value.content === 'string'
}),
@@ -693,9 +712,10 @@ App.prototype.streamEmojis = function () {
rel: 'mentions',
source: this.sbot.id,
dest: '&',
- values: true
+ values: true,
+ meta: false // emulate private:true
}),
- this.sbot.links({rel: 'mentions', dest: '&', values: true})
+ this.sbot.links({rel: 'mentions', dest: '&', values: true, meta: false})
]),
this.unboxMessages(),
pull.map(function (msg) { return msg.value.content.mentions }),
@@ -777,7 +797,7 @@ App.prototype.streamPrivate = function (opts) {
return this.filter(this.sbot.private, opts, {})
return pull(
- this.createLogStream(u.mergeOpts(opts)),
+ this.createLogStream(u.mergeOpts(opts, {private: true})),
pull.filter(u.isMsgEncrypted),
this.unboxMessages(),
pull.filter(u.isMsgReadable)
@@ -1218,7 +1238,8 @@ App.prototype.getLineComments = function (opts, cb) {
self.sbot.links({
dest: updateId,
rel: 'updateId',
- values: true
+ values: true,
+ meta: false,
}),
pull.filter(function (msg) {
var c = msg && msg.value && msg.value.content
@@ -1276,6 +1297,7 @@ App.prototype.getThread = function (msg) {
]
}) : this.sbotLinks({
dest: msg.key,
+ meta: false,
values: true
})
])
@@ -1288,6 +1310,7 @@ App.prototype.getLinks = function (id) {
]
}) : this.sbotLinks({
dest: id,
+ meta: false,
values: true
})
}