Files: 0c32ba4ecf1c98ab797d92daa8ee0bfa0f1f4fa5 / modules / feed / pull / private.js
871 bytesRaw
1 | const pull = require('pull-stream') |
2 | const nest = require('depnest') |
3 | const defer = require('pull-defer') |
4 | const onceTrue = require('mutant/once-true') |
5 | |
6 | exports.gives = nest('feed.pull.private') |
7 | exports.needs = nest({ |
8 | 'sbot.obs.connection': 'first' |
9 | }) |
10 | |
11 | exports.create = function (api) { |
12 | return nest('feed.pull.private', function (opts) { |
13 | // HACK: needed to select correct index and handle lt |
14 | |
15 | opts.query = [ |
16 | {$filter: { |
17 | timestamp: opts.lt |
18 | ? {$lt: opts.lt} |
19 | : {$gt: 0} |
20 | }} |
21 | ] |
22 | |
23 | delete opts.lt |
24 | |
25 | return StreamWhenConnected(api.sbot.obs.connection, (sbot) => { |
26 | return pull( |
27 | sbot.private.read(opts) |
28 | ) |
29 | }) |
30 | }) |
31 | } |
32 | |
33 | function StreamWhenConnected (connection, fn) { |
34 | var stream = defer.source() |
35 | onceTrue(connection, function (connection) { |
36 | stream.resolve(fn(connection)) |
37 | }) |
38 | return stream |
39 | } |
40 |
Built with git-ssb-web