File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed
Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -2016,6 +2016,7 @@ function createMockPollWithVotes(
20162016 } ) || [ ] ;
20172017
20182018 const votesByOption = new Map ( ) ;
2019+ const uniqueVoterIds = new Set ( ) ;
20192020 let totalNumVotes = 0 ;
20202021
20212022 resolvedVotes . forEach ( vote => {
@@ -2024,6 +2025,7 @@ function createMockPollWithVotes(
20242025 votesByOption . set ( index , [ ] ) ;
20252026 }
20262027 votesByOption . get ( index ) . push ( vote ) ;
2028+ uniqueVoterIds . add ( vote . from . id ) ;
20272029 totalNumVotes += 1 ;
20282030 } ) ;
20292031 } ) ;
@@ -2034,6 +2036,7 @@ function createMockPollWithVotes(
20342036 allowMultiple,
20352037 votesByOption,
20362038 totalNumVotes,
2039+ uniqueVoters : uniqueVoterIds . size ,
20372040 terminatedAt,
20382041 votes : votes ?. map ( v => ( {
20392042 fromConversationId : v . fromId ,
@@ -2053,6 +2056,7 @@ Poll.args = {
20532056 allowMultiple : false ,
20542057 votesByOption : new Map ( ) ,
20552058 totalNumVotes : 0 ,
2059+ uniqueVoters : 0 ,
20562060 } ,
20572061 status : 'sent' ,
20582062} ;
@@ -2066,6 +2070,7 @@ PollMultipleChoice.args = {
20662070 allowMultiple : true ,
20672071 votesByOption : new Map ( ) ,
20682072 totalNumVotes : 0 ,
2073+ uniqueVoters : 0 ,
20692074 } ,
20702075 status : 'sent' ,
20712076} ;
Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ export function PollMessageContents({
100100 const [ showVotesModal , setShowVotesModal ] = useState ( false ) ;
101101 const isIncoming = direction === 'incoming' ;
102102
103- const totalVotes = poll . totalNumVotes ;
103+ const { totalNumVotes : totalVotes , uniqueVoters } = poll ;
104104
105105 let pollStatusText : string ;
106106 if ( poll . terminatedAt ) {
@@ -167,7 +167,7 @@ export function PollMessageContents({
167167 const pollVoteEntries = poll . votesByOption . get ( index ) ;
168168 const optionVotes = pollVoteEntries ?. length ?? 0 ;
169169 const percentage =
170- totalVotes > 0 ? ( optionVotes / totalVotes ) * 100 : 0 ;
170+ uniqueVoters > 0 ? ( optionVotes / uniqueVoters ) * 100 : 0 ;
171171
172172 const weVotedForThis = ( pollVoteEntries ?? [ ] ) . some ( v => v . isMe ) ;
173173
Original file line number Diff line number Diff line change @@ -505,6 +505,7 @@ export type PollVoteWithUserType = {
505505export type PollWithResolvedVotersType = PollMessageAttribute & {
506506 votesByOption : Map < number , ReadonlyArray < PollVoteWithUserType > > ;
507507 totalNumVotes : number ;
508+ uniqueVoters : number ;
508509} ;
509510
510511const getPollForMessage = (
@@ -527,6 +528,7 @@ const getPollForMessage = (
527528 ...poll ,
528529 votesByOption : new Map ( ) ,
529530 totalNumVotes : 0 ,
531+ uniqueVoters : 0 ,
530532 } ;
531533 }
532534
@@ -573,6 +575,7 @@ const getPollForMessage = (
573575 } ) ;
574576
575577 const votesByOption = new Map < number , Array < PollVoteWithUserType > > ( ) ;
578+ const uniqueVoterIds = new Set ( ) ;
576579 let totalNumVotes = 0 ;
577580
578581 for ( const vote of resolvedVotes ) {
@@ -583,6 +586,7 @@ const getPollForMessage = (
583586 const votes = votesByOption . get ( optionIndex ) ;
584587 strictAssert ( ! ! votes , 'votes should exist' ) ;
585588 votes . push ( vote ) ;
589+ uniqueVoterIds . add ( vote . from . id ) ;
586590 totalNumVotes += 1 ;
587591 }
588592 }
@@ -591,6 +595,7 @@ const getPollForMessage = (
591595 ...poll ,
592596 votesByOption,
593597 totalNumVotes,
598+ uniqueVoters : uniqueVoterIds . size ,
594599 } ;
595600} ;
596601
You can’t perform that action at this time.
0 commit comments