Files: 0b68762e851dab73abc45fa60add0d96d3b5c7ac / feed / pull / private.js
1055 bytesRaw
1 | const nest = require('depnest') |
2 | const defer = require('pull-defer') |
3 | const pull = require('pull-stream') |
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 | // handle last item passed in as lt |
14 | var lt = (opts.lt && opts.lt.value) |
15 | ? opts.lt.timestamp |
16 | : opts.lt |
17 | delete opts.lt |
18 | |
19 | // HACK: needed to select correct index and handle lt |
20 | opts.query = [ |
21 | {$filter: { |
22 | timestamp: typeof lt === 'number' |
23 | ? {$lt: lt, $gt: 0} |
24 | : {$gt: 0} |
25 | }} |
26 | ] |
27 | |
28 | return StreamWhenConnected(api.sbot.obs.connection, (sbot) => { |
29 | if (!sbot.private || !sbot.private.read) return pull.empty() |
30 | return sbot.private.read(opts) |
31 | }) |
32 | }) |
33 | } |
34 | |
35 | function StreamWhenConnected (connection, fn) { |
36 | var stream = defer.source() |
37 | onceTrue(connection, function (connection) { |
38 | stream.resolve(fn(connection)) |
39 | }) |
40 | return stream |
41 | } |
42 |
Built with git-ssb-web