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