Fix double polls (#18)

This commit is contained in:
Szymon Szlachtowicz 2021-08-20 09:13:18 +02:00 committed by GitHub
parent 5e35a23574
commit 236dc028aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 5 deletions

View File

@ -38,6 +38,7 @@ class WakuVoting {
private timedPollInitMessages: PollInitMsg[] = []
private timedPollVotesMessages: TimedPollVoteMsg[] = []
private asyncUpdating = false
private static async createWaku() {
const waku = await Waku.create()
@ -135,17 +136,23 @@ class WakuVoting {
}
public async getDetailedTimedPolls() {
const { polls, updatedPolls } = await this.getTimedPolls()
const { votes, updatedVotes } = await this.getTimedPollsVotes()
let updated = false
if (!this.asyncUpdating) {
this.asyncUpdating = true
const { polls, updatedPolls } = await this.getTimedPolls()
const { votes, updatedVotes } = await this.getTimedPollsVotes()
updated = updatedPolls || updatedVotes
this.asyncUpdating = false
}
return {
DetailedTimedPolls: polls.map(
DetailedTimedPolls: this.timedPollInitMessages.map(
(poll) =>
new DetailedTimedPoll(
poll,
votes.filter((vote) => vote.id === poll.id)
this.timedPollVotesMessages.filter((vote) => vote.id === poll.id)
)
),
updated: updatedPolls || updatedVotes,
updated,
}
}
}