var Reduce = require('./reduce') var pull = require('pull-stream') module.exports = function (sbot, opts, cb) { if("string" == typeof opts) opts = {id: opts, private: false} var id = opts.id sbot.get(opts, function (err, msg) { if(err) return cb(err) var seen = {} if(msg.content.type !== 'gathering') return cb(new Error('not a gathering, was:'+msg.content.type)) var root = {key:id, value: msg} seen[id] = true console.log('gathering', opts) pull( sbot.links({ dest: id, values: true, rel: opts.replies ? undefined : 'about' }), pull.filter(function (data) { var type = data.value.content.type //exclude backlinking posts, except replies if(type == 'post' && data.value.content.root != id) return //the root message is type gathering //I really think the "about" message is heavily overloaded if(type !== 'gathering' && type !== 'about' && type !== 'post') return if(seen[data.key]) return false return seen[data.key] = true }), pull.collect(function (err, ary) { if(err) return cb(err) ary.unshift(root) var r = Reduce(ary) cb(null, r) }) ) }) }