From 34bf49e52db38a53d14c19c65d775f52da0c1329 Mon Sep 17 00:00:00 2001 From: cel Date: Fri, 14 Apr 2017 00:48:57 -0700 Subject: Move message stream decryption into App --- lib/app.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/app.js') 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() + ) +} -- cgit v1.2.3