git ssb

10+

Matt McKegg / patchwork



Tree: 3043037e5920603ef66d72b8f0ee962925650cca

Files: 3043037e5920603ef66d72b8f0ee962925650cca / modules / feed / pull / private.js

892 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) => {
25 return (sbot.private && sbot.private.read || pull.empty)(opts)
26 })
27 })
28}
29
30function StreamWhenConnected (connection, fn) {
31 var stream = defer.source()
32 onceTrue(connection, function (connection) {
33 stream.resolve(fn(connection))
34 })
35 return stream
36}
37

Built with git-ssb-web