Files: 7672098be439d5c9a07c4bbc2bd066d84993695f / get.js
1235 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 | |
12 | if(msg.content.type !== 'gathering') |
13 | return cb(new Error('not a gathering, was:'+msg.content.type)) |
14 | var root = {key:id, value: msg} |
15 | seen[id] = true |
16 | pull( |
17 | sbot.links({ |
18 | dest: id, values: true, |
19 | rel: opts.replies ? undefined : 'about' |
20 | }), |
21 | pull.filter(function (data) { |
22 | var type = data.value.content.type |
23 | //exclude backlinking posts, except replies |
24 | if(type == 'post' && data.value.content.root != id) |
25 | return |
26 | //the root message is type gathering |
27 | //I really think the "about" message is heavily overloaded |
28 | if(type !== 'gathering' && type !== 'about' && type !== 'post') |
29 | return |
30 | |
31 | if(seen[data.key]) return false |
32 | return seen[data.key] = true |
33 | }), |
34 | pull.collect(function (err, ary) { |
35 | if(err) return cb(err) |
36 | ary.unshift(root) |
37 | var r = Reduce(ary) |
38 | cb(null, r) |
39 | }) |
40 | ) |
41 | }) |
42 | } |
43 |
Built with git-ssb-web