git ssb

10+

Matt McKegg / patchwork



Tree: 2d1ca2e5040c8e453ac71fd7c4ec3918c596ae85

Files: 2d1ca2e5040c8e453ac71fd7c4ec3918c596ae85 / modules / feed / pull / private.js

871 bytesRaw
1const pull = require('pull-stream')
2const nest = require('depnest')
3const defer = require('pull-defer')
4const onceTrue = require('mutant/once-true')
5
6exports.gives = nest('feed.pull.private')
7exports.needs = nest({
8 'sbot.obs.connection': 'first'
9})
10
11exports.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
33function 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