git ssb

0+

Dominic / yap-gatherings



Tree: 98fd28641650bead5543428cdffb2bc932dbb165

Files: 98fd28641650bead5543428cdffb2bc932dbb165 / get.js

1274 bytesRaw
1var Reduce = require('./reduce')
2var pull = require('pull-stream')
3
4module.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 console.log('gathering', opts)
17 pull(
18 sbot.links({
19 dest: id, values: true,
20 rel: opts.replies ? undefined : 'about'
21 }),
22 pull.filter(function (data) {
23 var type = data.value.content.type
24 //exclude backlinking posts, except replies
25 if(type == 'post' && data.value.content.root != id)
26 return
27 //the root message is type gathering
28 //I really think the "about" message is heavily overloaded
29 if(type !== 'gathering' && type !== 'about' && type !== 'post')
30 return
31
32 if(seen[data.key]) return false
33 return seen[data.key] = true
34 }),
35 pull.collect(function (err, ary) {
36 if(err) return cb(err)
37 ary.unshift(root)
38 var r = Reduce(ary)
39 cb(null, r)
40 })
41 )
42 })
43}
44
45
46
47
48

Built with git-ssb-web