Files: 37af73bc5ddcbd3b63159caf24f253e95f6f3664 / feed / pull / with-replies.js
884 bytesRaw
1 | var pull = require('pull-stream') |
2 | var nest = require('depnest') |
3 | var extend = require('xtend') |
4 | var resolve = require('mutant/resolve') |
5 | var onceTrue = require('mutant/once-true') |
6 | |
7 | exports.needs = nest({ |
8 | 'backlinks.obs.for': 'first', |
9 | 'message.sync.isBlocked': 'first', |
10 | 'message.sync.root': 'first' |
11 | }) |
12 | |
13 | exports.gives = nest('feed.pull.withReplies', true) |
14 | |
15 | exports.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