git ssb

0+

Piet / ssb-loomio



Commit 153b2ae34195193ff8c51e32d55de4ba79ea73b5

add myPosition to the pollDoc returned by get

mix irving committed on 5/5/2018, 8:29:31 AM
Parent: 3f4d140a4dd5dc3eb9a025d3d8a9e6272156a067

Files changed

poll/async/get.jschanged
poll/async/get.jsView
@@ -9,8 +9,10 @@
99 const publishChooseOnePosition = require('../../position/async/buildChooseOne')
1010
1111 module.exports = function (server) {
1212 return function get (key, cb) {
13+ const myKey = server.id
14+
1315 server.get(key, (err, value) => {
1416 if (err) return cb(err)
1517
1618 var poll = { key, value }
@@ -20,9 +22,9 @@
2022 createBacklinkStream(key),
2123 pull.collect((err, msgs) => {
2224 if (err) return cb(err)
2325
24- cb(null, decoratePoll(poll, msgs))
26+ cb(null, decoratePoll(poll, msgs, myKey))
2527 })
2628 )
2729 })
2830 }
@@ -40,9 +42,9 @@
4042 })
4143 }
4244 }
4345
44-function decoratePoll (rawPoll, msgs = []) {
46+function decoratePoll (rawPoll, msgs = [], myKey) {
4547 const {
4648 author,
4749 content: {
4850 title,
@@ -91,8 +93,14 @@
9193 .map(position => {
9294 return decoratePosition({position, poll})
9395 })
9496
97+ poll.myPosition = poll.positions
98+ .filter(p => p.value.author === myKey)
99+ .sort((a, b) => {
100+ return a.value.timestamp > b.value.timestamp ? -1 : +1
101+ })[0]
102+
95103 poll.errors = msgs
96104 .filter(msg => msg.value.content.root === poll.key)
97105 .filter(msg => isPosition(msg) && !isPosition[type](msg))
98106 .map(position => {

Built with git-ssb-web