Files: 40388d6b54ff2c0d8c314271ce81dcbd0d3797d2 / modules / feed / pull / private.js
839 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) => sbot.private.read(opts)) |
25 | }) |
26 | } |
27 | |
28 | function StreamWhenConnected (connection, fn) { |
29 | var stream = defer.source() |
30 | onceTrue(connection, function (connection) { |
31 | stream.resolve(fn(connection)) |
32 | }) |
33 | return stream |
34 | } |
35 |
Built with git-ssb-web