Commit 77490f4b2f63287927764a378fde2beb51db0b1d
use ssb-private for private messages
Matt McKegg committed on 6/14/2017, 3:37:32 AMParent: c2865b1db3cc50c32ef351f6f877be6cafcf0381
Files changed
feed/pull/private.js | changed |
feed/pull/private.js | ||
---|---|---|
@@ -1,47 +1,35 @@ | ||
1 | -const pull = require('pull-stream') | |
2 | 1 … | const nest = require('depnest') |
3 | -const extend = require('xtend') | |
2 … | +const defer = require('pull-defer') | |
3 … | +const onceTrue = require('mutant/once-true') | |
4 | 4 … | |
5 | 5 … | exports.gives = nest('feed.pull.private') |
6 | 6 … | exports.needs = nest({ |
7 | - 'sbot.pull.log': 'first', | |
8 | - 'message.sync.unbox': 'first' | |
7 … | + 'sbot.obs.connection': 'first' | |
9 | 8 … | }) |
10 | 9 … | |
11 | 10 … | exports.create = function (api) { |
12 | 11 … | return nest('feed.pull.private', function (opts) { |
13 | - var opts = extend(opts) | |
12 … | + // HACK: needed to select correct index and handle lt | |
13 … | + opts.query = [ | |
14 … | + {$filter: { | |
15 … | + timestamp: opts.lt | |
16 … | + ? {$lt: opts.lt, $gt: 0} | |
17 … | + : {$gt: 0} | |
18 … | + }} | |
19 … | + ] | |
14 | 20 … | |
15 | - // handle limit to ensure we're getting old private messages | |
16 | - var limit = opts.limit | |
17 | - delete opts.limit | |
21 … | + delete opts.lt | |
18 | 22 … | |
19 | - var stream = pull( | |
20 | - api.sbot.pull.log(opts), | |
21 | - unbox() | |
22 | - ) | |
23 … | + return StreamWhenConnected(api.sbot.obs.connection, (sbot) => { | |
24 … | + return sbot.private.read(opts) | |
25 … | + }) | |
26 … | + }) | |
27 … | +} | |
23 | 28 … | |
24 | - if (limit) { | |
25 | - return pull( | |
26 | - stream, | |
27 | - pull.take(limit) | |
28 | - ) | |
29 | - } else { | |
30 | - return stream | |
31 | - } | |
29 … | +function StreamWhenConnected (connection, fn) { | |
30 … | + var stream = defer.source() | |
31 … | + onceTrue(connection, function (connection) { | |
32 … | + stream.resolve(fn(connection)) | |
32 | 33 … | }) |
33 | - | |
34 | - // scoped | |
35 | - | |
36 | - function unbox () { | |
37 | - return pull( | |
38 | - pull.filter(function (msg) { | |
39 | - return typeof msg.value.content === 'string' | |
40 | - }), | |
41 | - pull.map(function (msg) { | |
42 | - return api.message.sync.unbox(msg) | |
43 | - }), | |
44 | - pull.filter(Boolean) | |
45 | - ) | |
46 | - } | |
34 … | + return stream | |
47 | 35 … | } |
Built with git-ssb-web