var sort = require('ssb-sort') module.exports = function (thread) { thread = sort(thread) var r = thread.reduce(function (acc, data) { if(data.value.content.type == 'post') acc.replies.push(data) else { var c = data.value.content for(var k in c) //if(Object.hasOwnProperty(acc.value, k)) { if(Array.isArray(acc.value[k])) acc.value[k] = acc.value[k].concat(c[k]) else if(typeof c[k] == typeof acc.value[k]) acc.value[k] = c[k] //} } return acc }, { type: 'gathering', creator: thread[0].value.author, created: thread[0].value.timestamp, value:{ progenitor: '', startDateTime: {epoch: thread[0].value.timestamp, ts: ''}, title: '', location: '', description: '', image: {}, mentions: [], attendee: [] }, replies: [] }) r.root = thread[0].key r.branch = sort.heads(thread) return r }