aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-02-01 19:09:25 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2019-02-01 19:13:11 -1000
commita2d4c76879dc8c1aa10befd838f309c2e6daae15 (patch)
tree45f2e09ad1aa53f4738dfad6f27a7979a505ca98 /lib
parent0bc0c09ad6d0755d5978a4706fab8f0de26abe8e (diff)
downloadpatchfoo-a2d4c76879dc8c1aa10befd838f309c2e6daae15.tar.gz
patchfoo-a2d4c76879dc8c1aa10befd838f309c2e6daae15.zip
Support sbot built-in unboxing
This allows rendering private messages without the ssb-private plugin or old scuttlebot built-in private plugin /private is removed from default nav if there is no ssb-private plugin, because it emulates private.read by filtering the main log, which is inefficient/slow.
Diffstat (limited to 'lib')
-rw-r--r--lib/app.js45
-rw-r--r--lib/util.js4
2 files changed, 36 insertions, 13 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
})
}
diff --git a/lib/util.js b/lib/util.js
index 52c608b..5bd5f11 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -142,8 +142,8 @@ u.isMsgReadable = function (msg) {
}
u.isMsgEncrypted = function (msg) {
- var c = msg && msg.value.content
- return typeof c === 'string'
+ var value = msg && msg.value
+ return value && (value.private || typeof value.content === 'string')
}
u.pullConcat = function (cb) {