Commit 52f72d412dda4d495dd26c896b6703ecf5a8a612
PR review changes
mix irving committed on 3/9/2018, 5:04:33 AMParent: d8df11e7ac40f71635d7ffabe8a76e9fcd0a61fa
Files changed
poll/async/get.js | changed |
poll/async/get.js | |||
---|---|---|---|
@@ -1,9 +1,8 @@ | |||
1 | 1 … | const pull = require('pull-stream') | |
2 | 2 … | const sort = require('ssb-sort') | |
3 | 3 … | const isPoll = require('../../isPoll') | |
4 | 4 … | const isPosition = require('../../isPosition') | |
5 | -const isChooseOnePoll = require('../../poll/sync/isChooseOnePoll') | ||
6 | 5 … | const { ERROR_POSITION_TYPE } = require('../../types') | |
7 | 6 … | const getResults = require('../../position/sync/chooseOneResults') | |
8 | 7 … | const getMsgContent = require('../../lib/getMsgContent') | |
9 | 8 … | ||
@@ -40,11 +39,19 @@ | |||
40 | 39 … | } | |
41 | 40 … | } | |
42 | 41 … | ||
43 | 42 … | function decoratedPoll (rawPoll, msgs = []) { | |
44 | - const { author, content: { title, body } } = rawPoll.value | ||
43 … | + const { | ||
44 … | + author, | ||
45 … | + content: { | ||
46 … | + title, | ||
47 … | + body, | ||
48 … | + pollDetails: { type } | ||
49 … | + } | ||
50 … | + } = rawPoll.value | ||
45 | 51 … | ||
46 | 52 … | const poll = Object.assign({}, rawPoll, { | |
53 … | + type, | ||
47 | 54 … | author, | |
48 | 55 … | title, | |
49 | 56 … | body, | |
50 | 57 … | ||
@@ -57,11 +64,8 @@ | |||
57 | 64 … | ||
58 | 65 … | // TODO add missingContext warnings to each msg | |
59 | 66 … | msgs = sort(msgs) | |
60 | 67 … | ||
61 | - // filter position message into 'positions' and 'errors' | ||
62 | - const type = poll.value.content.pollDetails.type | ||
63 | - | ||
64 | 68 … | poll.positions = msgs | |
65 | 69 … | .filter(msg => msg.value.content.root === poll.key) | |
66 | 70 … | .filter(isPosition[type]) | |
67 | 71 … | .map(position => { | |
@@ -89,11 +93,12 @@ | |||
89 | 93 … | function decoratePosition ({position: rawPosition, poll: rawPoll}) { | |
90 | 94 … | var position = getMsgContent(rawPosition) | |
91 | 95 … | var poll = getMsgContent(rawPoll) | |
92 | 96 … | ||
97 … | + // NOTE this isn't deep enough to be a safe clone | ||
93 | 98 … | var newPosition = Object.assign({}, rawPosition) | |
94 | 99 … | ||
95 | - if (isChooseOnePoll(poll)) { | ||
100 … | + if (isPoll.chooseOne(poll)) { | ||
96 | 101 … | var choiceIndex = position.positionDetails.choice | |
97 | 102 … | newPosition.choice = poll.pollDetails.choices[choiceIndex] | |
98 | 103 … | } | |
99 | 104 … | return newPosition |
Built with git-ssb-web