git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 1cb5a37a32f05f213c4ce435539e108dc627b8d7

Files: 1cb5a37a32f05f213c4ce435539e108dc627b8d7 / 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