git ssb

7+

dinoworm ๐Ÿ› / patchcore



Tree: 37af73bc5ddcbd3b63159caf24f253e95f6f3664

Files: 37af73bc5ddcbd3b63159caf24f253e95f6f3664 / feed / pull / with-replies.js

884 bytesRaw
1var pull = require('pull-stream')
2var nest = require('depnest')
3var extend = require('xtend')
4var resolve = require('mutant/resolve')
5var onceTrue = require('mutant/once-true')
6
7exports.needs = nest({
8 'backlinks.obs.for': 'first',
9 'message.sync.isBlocked': 'first',
10 'message.sync.root': 'first'
11})
12
13exports.gives = nest('feed.pull.withReplies', true)
14
15exports.create = function (api) {
16 return nest('feed.pull.withReplies', function () {
17 return pull.asyncMap((rootMessage, cb) => {
18 // use global backlinks cache
19 var backlinks = api.backlinks.obs.for(rootMessage.key)
20 onceTrue(backlinks.sync, () => {
21 var replies = resolve(backlinks).filter(msg => {
22 return api.message.sync.root(msg) === rootMessage.key && !api.message.sync.isBlocked(msg, rootMessage)
23 })
24 cb(null, extend(rootMessage, { replies }))
25 })
26 })
27 })
28}
29

Built with git-ssb-web