git ssb

1+

Daan Patchwork / patchwork



Tree: 770fe5e2a3d5973a5c9b7d0945b214c3b2ea6793

Files: 770fe5e2a3d5973a5c9b7d0945b214c3b2ea6793 / lib / resolve-abouts.js

879 bytesRaw
1const pull = require('pull-stream')
2const extend = require('xtend')
3const Paramap = require('pull-paramap')
4
5module.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