git ssb

7+

dinoworm 🐛 / patchcore



Commit 77490f4b2f63287927764a378fde2beb51db0b1d

use ssb-private for private messages

Matt McKegg committed on 6/14/2017, 3:37:32 AM
Parent: c2865b1db3cc50c32ef351f6f877be6cafcf0381

Files changed

feed/pull/private.jschanged
feed/pull/private.jsView
@@ -1,47 +1,35 @@
1-const pull = require('pull-stream')
21 const nest = require('depnest')
3-const extend = require('xtend')
2 +const defer = require('pull-defer')
3 +const onceTrue = require('mutant/once-true')
44
55 exports.gives = nest('feed.pull.private')
66 exports.needs = nest({
7- 'sbot.pull.log': 'first',
8- 'message.sync.unbox': 'first'
7 + 'sbot.obs.connection': 'first'
98 })
109
1110 exports.create = function (api) {
1211 return nest('feed.pull.private', function (opts) {
13- var opts = extend(opts)
12 + // HACK: needed to select correct index and handle lt
13 + opts.query = [
14 + {$filter: {
15 + timestamp: opts.lt
16 + ? {$lt: opts.lt, $gt: 0}
17 + : {$gt: 0}
18 + }}
19 + ]
1420
15- // handle limit to ensure we're getting old private messages
16- var limit = opts.limit
17- delete opts.limit
21 + delete opts.lt
1822
19- var stream = pull(
20- api.sbot.pull.log(opts),
21- unbox()
22- )
23 + return StreamWhenConnected(api.sbot.obs.connection, (sbot) => {
24 + return sbot.private.read(opts)
25 + })
26 + })
27 +}
2328
24- if (limit) {
25- return pull(
26- stream,
27- pull.take(limit)
28- )
29- } else {
30- return stream
31- }
29 +function StreamWhenConnected (connection, fn) {
30 + var stream = defer.source()
31 + onceTrue(connection, function (connection) {
32 + stream.resolve(fn(connection))
3233 })
33-
34- // scoped
35-
36- function unbox () {
37- return pull(
38- pull.filter(function (msg) {
39- return typeof msg.value.content === 'string'
40- }),
41- pull.map(function (msg) {
42- return api.message.sync.unbox(msg)
43- }),
44- pull.filter(Boolean)
45- )
46- }
34 + return stream
4735 }

Built with git-ssb-web