Files: 4087ed91f7e663172d051c9afe142fa7b7669f1e / lib / resolve-abouts.js
879 bytesRaw
1 | const pull = require('pull-stream') |
2 | const extend = require('xtend') |
3 | const Paramap = require('pull-paramap') |
4 | |
5 | module.exports = function ({ ssb }) { |
6 | return pull( |
7 | Paramap((msg, cb) => { |
8 | const type = msg.value && msg.value.content && msg.value.content.type |
9 | if (type === 'gathering') { |
10 | resolveGathering(msg, cb) |
11 | } else { |
12 | cb(null, msg) |
13 | } |
14 | }, 10) |
15 | ) |
16 | |
17 | function resolveGathering (msg, cb) { |
18 | ssb.about.latestValues({ |
19 | keys: ['title', 'description', 'location', 'startDateTime', 'image'], |
20 | dest: msg.key |
21 | }, (err, gathering) => { |
22 | if (err) return cb(err) |
23 | ssb.about.socialValues({ |
24 | key: 'attendee', |
25 | dest: msg.key |
26 | }, (err, attending) => { |
27 | if (err) return cb(err) |
28 | gathering.attending = Object.keys(attending) |
29 | cb(null, extend(msg, { gathering })) |
30 | }) |
31 | }) |
32 | } |
33 | } |
34 |
Built with git-ssb-web