Commit 153b2ae34195193ff8c51e32d55de4ba79ea73b5
add myPosition to the pollDoc returned by get
mix irving committed on 5/5/2018, 8:29:31 AMParent: 3f4d140a4dd5dc3eb9a025d3d8a9e6272156a067
Files changed
poll/async/get.js | changed |
poll/async/get.js | ||
---|---|---|
@@ -9,8 +9,10 @@ | ||
9 | 9 | const publishChooseOnePosition = require('../../position/async/buildChooseOne') |
10 | 10 | |
11 | 11 | module.exports = function (server) { |
12 | 12 | return function get (key, cb) { |
13 | + const myKey = server.id | |
14 | + | |
13 | 15 | server.get(key, (err, value) => { |
14 | 16 | if (err) return cb(err) |
15 | 17 | |
16 | 18 | var poll = { key, value } |
@@ -20,9 +22,9 @@ | ||
20 | 22 | createBacklinkStream(key), |
21 | 23 | pull.collect((err, msgs) => { |
22 | 24 | if (err) return cb(err) |
23 | 25 | |
24 | - cb(null, decoratePoll(poll, msgs)) | |
26 | + cb(null, decoratePoll(poll, msgs, myKey)) | |
25 | 27 | }) |
26 | 28 | ) |
27 | 29 | }) |
28 | 30 | } |
@@ -40,9 +42,9 @@ | ||
40 | 42 | }) |
41 | 43 | } |
42 | 44 | } |
43 | 45 | |
44 | -function decoratePoll (rawPoll, msgs = []) { | |
46 | +function decoratePoll (rawPoll, msgs = [], myKey) { | |
45 | 47 | const { |
46 | 48 | author, |
47 | 49 | content: { |
48 | 50 | title, |
@@ -91,8 +93,14 @@ | ||
91 | 93 | .map(position => { |
92 | 94 | return decoratePosition({position, poll}) |
93 | 95 | }) |
94 | 96 | |
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 | + | |
95 | 103 | poll.errors = msgs |
96 | 104 | .filter(msg => msg.value.content.root === poll.key) |
97 | 105 | .filter(msg => isPosition(msg) && !isPosition[type](msg)) |
98 | 106 | .map(position => { |
Built with git-ssb-web