git ssb

0+

Dominic / yap-gatherings



Tree: c41a27a2d832340a4e31d5f78b95d182759bb0e2

Files: c41a27a2d832340a4e31d5f78b95d182759bb0e2 / reduce.js

984 bytesRaw
1var sort = require('ssb-sort')
2
3module.exports = function (thread) {
4 thread = sort(thread)
5 var r = thread.reduce(function (acc, data) {
6 if(data.value.content.type == 'post')
7 acc.replies.push(data)
8 else {
9 var c = data.value.content
10 for(var k in c)
11 //if(Object.hasOwnProperty(acc.value, k)) {
12 if(Array.isArray(acc.value[k]))
13 acc.value[k] = acc.value[k].concat(c[k])
14 else if(typeof c[k] == typeof acc.value[k])
15 acc.value[k] = c[k]
16 //}
17 }
18 return acc
19 }, {
20 type: 'gathering',
21 creator: thread[0].value.author,
22 created: thread[0].value.timestamp,
23 value:{
24 progenitor: '',
25 startDateTime: {epoch: thread[0].value.timestamp, ts: ''},
26 title: '',
27 location: '',
28 description: '',
29 image: {},
30 mentions: [],
31 attendee: []
32 },
33 replies: []
34 })
35 r.root = thread[0].key
36 r.branch = sort.heads(thread)
37 return r
38}
39
40

Built with git-ssb-web