Commit e31a903a21d0c16d542f0c003a6e02ec53fda004
Merge pull request #42 from ssbc/withReplies-feed
split out backlink reply mapping into its own file (so it can be used on its own)Matt McKegg authored on 11/6/2017, 12:24:05 PM
GitHub committed on 11/6/2017, 12:24:05 PM
Parent: 976c30737c785b36ead8a46a000292626e4e32c9
Parent: 06f5ffeda817c287c27c5efa159dd4e31b28b3f9
Files changed
feed/pull/rollup.js | changed |
feed/pull/with-replies.js | added |
feed/pull/rollup.js | ||
---|---|---|
@@ -3,19 +3,17 @@ | ||
3 | 3 … | // accept prioritized list (render these first) |
4 | 4 … | |
5 | 5 … | var pull = require('pull-stream') |
6 | 6 … | var nest = require('depnest') |
7 | -var extend = require('xtend') | |
8 | 7 … | var HLRU = require('hashlru') |
9 | -var resolve = require('mutant/resolve') | |
10 | -var onceTrue = require('mutant/once-true') | |
11 | 8 … | |
12 | 9 … | exports.needs = nest({ |
13 | 10 … | 'backlinks.obs.for': 'first', |
14 | 11 … | 'sbot.async.get': 'first', |
15 | 12 … | 'message.sync.isBlocked': 'first', |
16 | 13 … | 'message.sync.root': 'first', |
17 | - 'message.sync.unbox': 'first' | |
14 … | + 'message.sync.unbox': 'first', | |
15 … | + 'feed.pull.withReplies': 'first' | |
18 | 16 … | }) |
19 | 17 … | |
20 | 18 … | exports.gives = nest('feed.pull.rollup', true) |
21 | 19 … | |
@@ -87,17 +85,8 @@ | ||
87 | 85 … | pull.filter(rootFilter || (() => true)), |
88 | 86 … | pull.filter(msg => !api.message.sync.isBlocked(msg)), |
89 | 87 … | |
90 | 88 … | // ADD REPLIES |
91 | - pull.asyncMap((rootMessage, cb) => { | |
92 | - // use global backlinks cache | |
93 | - var backlinks = api.backlinks.obs.for(rootMessage.key) | |
94 | - onceTrue(backlinks.sync, () => { | |
95 | - var replies = resolve(backlinks).filter(msg => { | |
96 | - return api.message.sync.root(msg) === rootMessage.key && !api.message.sync.isBlocked(msg) | |
97 | - }) | |
98 | - cb(null, extend(rootMessage, { replies })) | |
99 | - }) | |
100 | - }) | |
89 … | + api.feed.pull.withReplies() | |
101 | 90 … | ) |
102 | 91 … | }) |
103 | 92 … | } |
feed/pull/with-replies.js | ||
---|---|---|
@@ -1,0 +1,28 @@ | ||
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) | |
23 … | + }) | |
24 … | + cb(null, extend(rootMessage, { replies })) | |
25 … | + }) | |
26 … | + }) | |
27 … | + }) | |
28 … | +} |
Built with git-ssb-web