Commit 028237b4b26db208a93b7399ed9575c6608b1999
Merge branch 'master' into reducer-only-counts-latest-vote-by-author
mix irving committed on 3/9/2018, 5:21:43 AMParent: 6730668ae7223a39f319ed33a69019c0ef1d8c38
Parent: d73dadc02145f4bb0d854fedadb58c6caaef4b99
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 … | + details: { 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.details.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.details.choice |
97 | 102 … | newPosition.choice = poll.details.choices[choiceIndex] |
98 | 103 … | } |
99 | 104 … | return newPosition |
Built with git-ssb-web