git ssb

0+

mixmix / scuttle-gathering



Commit 7c528349577470dee18f77f63097c8b28f7825fa

collect and reduce image / images correctly

mixmix committed on 9/19/2018, 10:01:16 PM
Parent: e5f94aaca20e9b5e3a03c199dc585d0375451b5b

Files changed

gathering/async/get.jschanged
gathering/async/get.test.jschanged
gathering/async/get.jsView
@@ -15,10 +15,19 @@
1515
1616 const updates = backlinks
1717 .filter(isUpdate)
1818 .map(m => permittedOpts(m.value.content))
19- .reduce((acc, update) => merge(acc, update), {})
19 + .reduce((acc, update) => {
20 + const { image } = update
21 + if (image) {
22 + acc.image = image
23 + if (!acc.images.find(i => i.link === image.link)) acc.images.push(image)
24 + delete update.image
25 + }
2026
27 + return merge(acc, update)
28 + }, { images: [] })
29 +
2130 cb(null, merge(doc, updates))
2231 })
2332 })
2433 }
gathering/async/get.test.jsView
@@ -29,9 +29,20 @@
2929
3030 t.equal(doc.title, 'ziva\'s birthday', 'has title')
3131 t.deepEqual(doc.startDateTime, { epoch: now + 750, tz: 'Pacific/ Auckland' }, 'has edited time startDateTime')
3232 t.equal(doc.location, 'our place in mirimar')
33 + t.deepEqual(doc.image, { link: '&AnotherImage//z3os/qA9+YJndRmbJQXl8LYfBquz4=.sha256' }, 'has single image')
3334
35 + t.deepEqual(doc.images, [
36 + {
37 + link: '&l/Mr4CqSFYtCsrz3os/qA9+YJndRmbJQXl8LYfBquz4=.sha256',
38 + name: 'orange-grove-helpers.jpg',
39 + size: 1049416,
40 + type: 'image/jpeg'
41 + },
42 + { link: '&AnotherImage//z3os/qA9+YJndRmbJQXl8LYfBquz4=.sha256' }
43 + ], 'has all images added')
44 +
3445 done()
3546 })
3647 })
3748 })
@@ -45,8 +56,14 @@
4556 title: 'ziva\'s birthday',
4657 startDateTime: {
4758 epoch,
4859 tz: 'Pacific/ Auckland'
60 + },
61 + image: {
62 + link: '&l/Mr4CqSFYtCsrz3os/qA9+YJndRmbJQXl8LYfBquz4=.sha256',
63 + name: 'orange-grove-helpers.jpg',
64 + size: 1049416,
65 + type: 'image/jpeg'
4966 }
5067 }
5168 scuttle.gathering.async.publish(opts, (err, gathering) => {
5269 if (err) return cb(err)
@@ -54,9 +71,12 @@
5471 // make an update
5572 epoch = now + 750
5673 const opts = {
5774 startDateTime: { epoch },
58- location: 'our place in mirimar'
75 + location: 'our place in mirimar',
76 + image: {
77 + 'link': '&AnotherImage//z3os/qA9+YJndRmbJQXl8LYfBquz4=.sha256'
78 + }
5979 }
6080 scuttle.update.async.publish(gathering.key, opts, (err, update) => {
6181 if (err) return cb(err)
6282

Built with git-ssb-web