git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 0c32ba4ecf1c98ab797d92daa8ee0bfa0f1f4fa5

Files: 0c32ba4ecf1c98ab797d92daa8ee0bfa0f1f4fa5 / 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