git ssb

0+

Dominic / yap-gatherings



Tree: 37d41ff61b662f01ec14293463dbe5afff14adf0

Files: 37d41ff61b662f01ec14293463dbe5afff14adf0 / reduce.js

1019 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(acc)
8 else {
9 console.log('DATA', data)
10 var c = data.value.content
11 for(var k in c)
12 //if(Object.hasOwnProperty(acc.value, k)) {
13 if(Array.isArray(acc.value[k]))
14 acc.value[k] = acc.value[k].concat(c[k])
15 else if(typeof c[k] == typeof acc.value[k])
16 acc.value[k] = c[k]
17 //}
18 }
19 return acc
20 }, {
21 type: 'gathering',
22 creator: thread[0].value.author,
23 created: thread[0].value.timestamp,
24 value:{
25 progenitor: '',
26 startDateTime: {epoch: thread[0].value.timestamp, ts: ''},
27 title: '',
28 location: '',
29 description: '',
30 image: {},
31 mentions: [],
32 attendee: []
33 },
34 replies: []
35 })
36 r.root = thread[0].key
37 r.branch = sort.heads(thread)
38 return r
39}
40
41
42
43
44
45

Built with git-ssb-web