aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-04-14 00:48:57 -0700
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-04-14 12:57:34 -0700
commit34bf49e52db38a53d14c19c65d775f52da0c1329 (patch)
tree609af342a5dce6a599bbca6cca41cc3f081256fc
parent3b2abbd473b007b9de5f8b76c8e74aad26b947be (diff)
downloadpatchfoo-34bf49e52db38a53d14c19c65d775f52da0c1329.tar.gz
patchfoo-34bf49e52db38a53d14c19c65d775f52da0c1329.zip
Move message stream decryption into App
-rw-r--r--lib/app.js24
-rw-r--r--lib/serve.js20
2 files changed, 28 insertions, 16 deletions
diff --git a/lib/app.js b/lib/app.js
index 38f9f50..7424b50 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -7,12 +7,18 @@ var pull = require('pull-stream')
var ssbAvatar = require('ssb-avatar')
var hasher = require('pull-hash/ext/ssb')
var multicb = require('multicb')
+var paramap = require('pull-paramap')
var Serve = require('./serve')
var Render = require('./render')
module.exports = App
+function isMsgReadable(msg) {
+ var c = msg && msg.value && msg.value.content
+ return typeof c === 'object' && c !== null
+}
+
function App(sbot, config) {
this.sbot = sbot
this.config = config
@@ -278,3 +284,21 @@ App.prototype._getFriendInfo = function (id, cb) {
})
})
}
+
+App.prototype.unboxMessages = function () {
+ return pull(
+ paramap(this.unboxMsg, 16),
+ pull.filter(isMsgReadable)
+ )
+}
+
+App.prototype.streamChannels = function (opts) {
+ return pull(
+ this.sbot.messagesByType({type: 'channel', reverse: true}),
+ this.unboxMessages(),
+ pull.map(function (msg) {
+ return msg.value.content.channel
+ }),
+ pull.unique()
+ )
+}
diff --git a/lib/serve.js b/lib/serve.js
index ca86533..e7d1695 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -25,11 +25,6 @@ var emojiDir = path.join(require.resolve('emoji-named-characters'), '../pngs')
var urlIdRegex = /^(?:\/+(([%&@]|%25)(?:[A-Za-z0-9\/+]|%2[Ff]|%2[Bb]){43}(?:=|%3D)\.(?:sha256|ed25519))(?:\.([^?]*))?|(\/.*?))(?:\?(.*))?$/
-function isMsgReadable(msg) {
- var c = msg && msg.value.content
- return typeof c === 'object' && c !== null
-}
-
function isMsgEncrypted(msg) {
var c = msg && msg.value.content
return typeof c === 'string'
@@ -323,8 +318,7 @@ Serve.prototype.private = function (ext) {
pull(
this.app.createLogStream(opts),
pull.filter(isMsgEncrypted),
- paramap(this.app.unboxMsg, 16),
- pull.filter(isMsgReadable),
+ this.app.unboxMessages(),
pull.take(limit),
this.renderThreadPaginated(opts, null, q),
this.wrapMessages(),
@@ -412,13 +406,7 @@ Serve.prototype.channels = function (ext) {
var self = this
pull(
- self.app.sbot.messagesByType({type: 'channel', reverse: true}),
- paramap(self.app.unboxMsg, 16),
- pull.map(function (msg) {
- var c = msg.value.content
- return c && c.channel
- }),
- pull.unique(),
+ self.app.streamChannels(),
paramap(function (channel, cb) {
var subscribed = false
cb(null, h('form', {method: 'post', action: ''},
@@ -565,7 +553,7 @@ Serve.prototype.id = function (id, ext) {
pull(
cat([pull.once(rootMsg), self.app.sbot.links({dest: id, values: true})]),
pull.unique('key'),
- paramap(self.app.unboxMsg, 16),
+ self.app.unboxMessages(),
pull.collect(function (err, links) {
if (err) return self.respond(500, err.stack || err)
pull(
@@ -1230,7 +1218,7 @@ Serve.prototype.composer = function (opts, cb) {
var msgContainer = h('table.ssb-msgs')
pull(
pull.once(msg),
- pull.asyncMap(self.app.unboxMsg),
+ self.app.unboxMessages(),
self.app.render.renderFeeds(raw),
pull.drain(function (el) {
msgContainer.appendChild(h('tbody', el))