git ssb

10+

Matt McKegg / patchwork



Tree: 42cae2aa63c9ac20f1bbba02550d98ed4ec680e5

Files: 42cae2aa63c9ac20f1bbba02550d98ed4ec680e5 / modules / feed / pull / private.js

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