Files: 37d41ff61b662f01ec14293463dbe5afff14adf0 / get.js
1215 bytesRaw
1 | var Reduce = require('./reduce') |
2 | var pull = require('pull-stream') |
3 | |
4 | module.exports = function (sbot, opts, cb) { |
5 | if("string" == typeof opts) |
6 | opts = {id: opts, private: false} |
7 | var id = opts.id |
8 | sbot.get(opts, function (err, msg) { |
9 | if(err) return cb(err) |
10 | var seen = {} |
11 | if(msg.content.type !== 'gathering') |
12 | return cb(new Error('not a gathering, was:'+msg.content.type)) |
13 | var root = {key:id, value: msg} |
14 | seen[id] = true |
15 | pull( |
16 | sbot.links({ |
17 | dest: id, values: true, |
18 | rel: opts.replies ? undefined : 'about' |
19 | }), |
20 | pull.filter(function (data) { |
21 | var type = data.value.content.type |
22 | //exclude backlinking posts, except replies |
23 | if(type == 'post' && data.value.content.root != id) |
24 | return |
25 | //the root message is type gathering |
26 | //I really think the "about" message is heavily overloaded |
27 | if(type !== 'gathering' && type !== 'about') |
28 | return |
29 | if(seen[data.key]) return false |
30 | return seen[data.key] = true |
31 | }), |
32 | pull.collect(function (err, ary) { |
33 | if(err) return cb(err) |
34 | ary.unshift(root) |
35 | var r = Reduce(ary) |
36 | cb(null, r) |
37 | }) |
38 | ) |
39 | }) |
40 | } |
41 | |
42 |
Built with git-ssb-web